rstudio/bookdown

Table does not show in gitbook format (html)

Closed this issue · 4 comments

My table renders fine into PDF. But when I render the site to be viewed online, the same table does not show. I don't know what I am doing wrong.

Any help would be greatly appreciated.

Index.Rmd

--- 
title: "Teaching Stats with JASP"
author: "Ovande Furtado, Jr."
date: "`r Sys.Date()`"
output:
  html_document:
    df_print: paged
documentclass: book
bibliography:
- book.bib
- packages.bib
biblio-style: apalike
csl: apa-numeric-superscript-brackets.csl
link-citations: yes
description: A Guide to Data Analysis & Interpretation
site: bookdown::bookdown_site
---

_output.yml

bookdown::gitbook:
  split_bib: yes
  highlight: tango
  css: style.css
  config:
    toc:
      before: |
        <li><a href="./">Teaching Statistics with JASP</a></li>
      after: |
        <li><a href="https://github.com/rstudio/bookdown" target="blank">Published with bookdown</a></li>
    download: ["pdf", "epub"]
bookdown::pdf_book:
  includes:
    in_header: preamble.tex
  latex_engine: xelatex
  citation_package: natbib
  bilbio-style: apa_like
  keep_tex: yes
bookdown::epub_book: default
bookdown::html_book:
  css: toc.css

_bookdown.yml

book_filename: "tjs"
output_dir: "docs"
delete_merged_file: true
language:
  ui:
    chapter_name: "Chapter "
rmd_files: ["index.Rmd", "01-intro.Rmd", "02-correlation.Rmd", "03-method.Rmd","appendices.Rmd","06-references.Rmd"]

preamble.tex

\usepackage{booktabs}
\usepackage{longtable}
\usepackage{array}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{float}
\usepackage{colortbl}
\usepackage{pdflscape}
\usepackage{tabu}
\usepackage{threeparttable}
\usepackage{threeparttablex}
\usepackage[normalem]{ulem}
\usepackage{makecell}
\usepackage{xcolor}

\ifxetex
  \usepackage{letltxmacro}
  \setlength{\XeTeXLinkMargin}{1pt}
  \LetLtxMacro\SavedIncludeGraphics\includegraphics
  \def\includegraphics#1#{% #1 catches optional stuff (star/opt. arg.)
    \IncludeGraphicsAux{#1}%
  }%
  \newcommand*{\IncludeGraphicsAux}[2]{%
    \XeTeXLinkBox{%
      \SavedIncludeGraphics#1{#2}%
    }%
  }%
\fi

03-method.Rmd

# Methods

`Something here`

```{=tex}
\begin{table}[h]
    \centering
    \caption{Independent Samples T-Test}
    \label{tab:independentSamplesT-Test}
    {
        \begin{tabular}{lrrrrrr}
            \toprule
            \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{2}{c}{95\% CI for Cohen's d} \\
            \cline{6-7}
              & t & df & p & Cohen's d & Lower & Upper  \\
            \cmidrule[0.4pt]{1-7}
            engagement & 2.365 & 38 & 0.023 & 0.748 & 0.101 & 1.385  \\
            \bottomrule
            % \addlinespace[1ex]
            % \multicolumn{7}{p{0.5\linewidth}}{\textit{Note.} Student's t-test.} \\
        \end{tabular}
    }
\end{table}

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('bookdown'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('rstudio/bookdown').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

cderv commented

when I render the site to be viewed online

Do you mean online version as an online PDF or the HTML gitbook() format ?

For the latter, you won't see your table in an HTML output because your table in written in LaTeX. You even use raw block with tex attribute to say to Pandoc, this is TeX. HTML does not support TeX syntax so it will be ignore during the conversion - hence no table at the end.

If you want cross format output, you'll need to use cross format tools. Table is mentioned in https://bookdown.org/yihui/bookdown/tables.html and also in https://bookdown.org/yihui/rmarkdown-cookbook/tables.html

You may also read more on how R Markdown is working on the inside to understand how the conversion works. It uses Pandoc to make the conversion from a Pandoc Markdown file to other type of output. When you use specific raw content, it could be ignored by the conversion. (https://bookdown.org/yihui/rmarkdown-cookbook/raw-content.html

Does it make sense ?

when I render the site to be viewed online

Do you mean online version as an online PDF or the HTML gitbook() format ?

For the latter, you won't see your table in an HTML output because your table in written in LaTeX. You even use raw block with tex attribute to say to Pandoc, this is TeX. HTML does not support TeX syntax so it will be ignore during the conversion - hence no table at the end.

If you want cross format output, you'll need to use cross format tools. Table is mentioned in https://bookdown.org/yihui/bookdown/tables.html and also in https://bookdown.org/yihui/rmarkdown-cookbook/tables.html

You may also read more on how R Markdown is working on the inside to understand how the conversion works. It uses Pandoc to make the conversion from a Pandoc Markdown file to other type of output. When you use specific raw content, it could be ignored by the conversion. (https://bookdown.org/yihui/rmarkdown-cookbook/raw-content.html

Does it make sense ?

Yes, I meant to say gitbook() as the content of the book I am writing will be available online and in PDF.

I read the content from the links you provided but could not find a way to display the LaTex tables that are copied from a JASP output to a Rmarkdown file and display it online (gitbook). The book is about teaching stats with JASP and I would like to display the tables generated by JASP, which I can copy as LaTex.

cderv commented

If you want to include LaTeX rendered Table in an HTML output format, you'll need to render the table first and include the result.

I would have a look at the texPreview 📦

This will allow you to have some latex chunks rendered with a special engine to an image included in the HTML output.

You need a bit of a setup with all the TeX packages required but after it works really nice.

Example:

---
title: "test"
date: "`r Sys.Date()`"
output: html_document
---

```{r, setup}
library(texPreview)
```


```{texpreview, echo = FALSE}
\begin{table}[h]
    \centering
    \caption{Independent Samples T-Test}
    \label{tab:independentSamplesT-Test}
    {
        \begin{tabular}{lrrrrrr}
            \toprule
            \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{1}{c}{} & \multicolumn{2}{c}{95\% CI for Cohen's d} \\
            \cline{6-7}
              & t & df & p & Cohen's d & Lower & Upper  \\
            \cmidrule[0.4pt]{1-7}
            engagement & 2.365 & 38 & 0.023 & 0.748 & 0.101 & 1.385  \\
            \bottomrule
            % \addlinespace[1ex]
            % \multicolumn{7}{p{0.5\linewidth}}{\textit{Note.} Student's t-test.} \\
        \end{tabular}
    }
\end{table}
```

image

There is not issue with bookdown here so I'll close this.

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.