rstudio / rticles

LaTeX Journal Article Templates for R Markdown
https://pkgs.rstudio.com/rticles/
1.47k stars 520 forks source link

! LaTeX Error: Environment longtable undefined. #93

Closed xhie closed 6 years ago

xhie commented 8 years ago

I'm using the ACS template and it can compile a simple markdown table. This is the error from rmarkdown :

! LaTeX Error: Environment longtable undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.124 \begin{longtable}

pandoc: Error producing PDF from TeX source
Error: pandoc document conversion failed with error 43
Execution halted

And the latex table is:

\begin{longtable}[c]{@{}lll@{}}
\toprule
CETESB & SP Trans Urban Bus (UB) & REMI\tabularnewline
\midrule
\endhead
Urban Buses & Bi Articulated (BAUB) & Ubus Artic
\textgreater{}18t\tabularnewline
Urban Buses & Articulated (AUB) & Ubus Artic
\textgreater{}18t\tabularnewline
Urban Buses & Basic (BUB) & Ubus Std \textgreater{}15-18t\tabularnewline
Urban Buses & Padron (P) & Ubus Std \textgreater{}15-18t\tabularnewline
Micro Bus & Minionibus (MoB) & Ubus Midi \textless{}=15t\tabularnewline
Micro Bus & Midionibus (MdB) & Ubus Midi \textless{}=15t\tabularnewline
Micro Bus & Minibus (MiB) & Ubus Midi \textless{}=15t\tabularnewline
Motorway Bus & nobs & Coach 3-Axes \textgreater{}18t\tabularnewline
\bottomrule
\end{longtable}

Thanks

ehrlinger commented 7 years ago

FWIW, I got this working by modifying the kable call to include:

kable(..., format = "latex" )

without adding a preamble: > or tables: true statement into the yaml headers.

I'd still like to use booktabs = TRUE, which does not work yet and may require an alternative header statement in the yaml. preamble: > \usepackage{booktabs} does not seem to work.

ehrlinger commented 7 years ago

Actually: Using

output: 
  rticles::acm_article:
    citation_package: natbib
    keep_tex: true
    number_sections: true

Then examining the .tex file, it appears rticles (at least acm) does not respect citation_package, preamble:, header-includes: or

      includes:
            in_header: mystyles.sty
mebrooks commented 7 years ago

Hi, I'm getting the same error message. I'm trying to draw a table with text. The following table is fine in an rmd file with output: pdf_document at the top, but gives the error in when I specify output: rticles::rjournal_article.

feature    | header 1    | header 2 
---------- | ----------- | ---------
   w       | h           |  y    
           |             |

@ehrlinger , it sounds like you found a solution, but I don't quite understand it. I'm not familiar with many advanced features of RMarkdown. Can you explain this at a more basic level? Or can anyone else suggest a solution?

mebrooks commented 7 years ago

I managed to get the table into my document by writing it in LaTeX code since that's what the output of kable(..., format = "latex" ) would look like and you said that would work. So at least there's a workaround :)

yihui commented 6 years ago

Using in_header under includes should be a universal solution to the problem of failing to include a LaTeX package, e.g.,

output: 
  rticles::acm_article:
    includes:
      in_header: preamble.tex

In preamble.tex, you can load any LaTeX packaegs (e.g., \usepackage{longtable}).

Note that I said this was a universal solution, so it is not limited to rticles::acm_article, and should apply to any LaTeX-based output formats. See Section 3.3.7.3: https://bookdown.org/yihui/rmarkdown/pdf-document.html

Frank-Sw commented 5 years ago

Any idea on fill color for cell in longtable environment? I

github-actions[bot] commented 4 years ago

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.