Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kable with longtable=FALSE still produces longtable #1221

Closed
vsimko opened this issue Jun 7, 2016 · 4 comments
Closed

kable with longtable=FALSE still produces longtable #1221

vsimko opened this issue Jun 7, 2016 · 4 comments
Milestone

Comments

@vsimko
Copy link

vsimko commented Jun 7, 2016

The following code:

kable(head(cars), longtable = FALSE)

Produces:

\begin{longtable}[c]{@{}rr@{}}
\toprule
speed & dist\tabularnewline
\midrule
\endhead
4 & 2\tabularnewline
4 & 10\tabularnewline
7 & 4\tabularnewline
7 & 22\tabularnewline
8 & 16\tabularnewline
9 & 10\tabularnewline
\bottomrule
\end{longtable}

However, when format="latex" is added, the code:

kable(head(cars), longtable = FALSE, format = "latex")

Produces the expected output:

\begin{tabular}{r|r}
\hline
speed & dist\\
\hline
4 & 2\\
\hline
4 & 10\\
\hline
7 & 4\\
\hline
7 & 22\\
\hline
8 & 16\\
\hline
9 & 10\\
\hline
\end{tabular}

See also this reproducible example:
kable_issue.zip

@yihui
Copy link
Owner

yihui commented Jun 8, 2016

The default output is a markdown table when kable() is used in an Rmd document. It is Pandoc that converts the markdown table to longtable.

@vsimko
Copy link
Author

vsimko commented Jun 8, 2016

Then, it would be useful to inform the user that he shouldn't use longtable = FALSE when markdown is used - a warning perhaps.

@yihui
Copy link
Owner

yihui commented Jun 9, 2016

That makes sense. There is actually an internal hack that you may use: knitr::opts_knit$get(kable.force.latex = TRUE) After setting that, kable() will generate LaTeX tables if the output format is LaTeX.

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants