yihui / knitr

A general-purpose tool for dynamic report generation in R
https://yihui.org/knitr/
2.38k stars 873 forks source link

remove new line before table with kable for format LaTeX #1768

Open srnnkls opened 4 years ago

srnnkls commented 4 years ago

When calling cable with format = latex the actual latex output is preceded by a newline. I can write a wrapper that strips it but was curious: Is this intentional?

library(knitr)
a <- c(1, 2, 3) 
b <- kable(a, format = "latex")

b[1]
#> [1] "\n\\begin{tabular}{r}\n\\hline\nx\\\\\n\\hline\n1\\\\\n\\hline\n2\\\\\n\\hline\n3\\\\\n\\hline\n\\end{tabular}"

By filing an issue to this repo, I promise that

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

cderv commented 4 years ago

digging a bit doing source code archeology, I found that this newline was added in this commit https://github.com/yihui/knitr/commit/3dadff208a4c3c746a0bf5509cd5642bfbd7b022 7 years ago with message

add an empty line before the table; this is to make sure hook_movecode{} works well

and this was before adding some new lines above it in the longtable environment.

I guess only a few tests can tell us if this is still an issue or not...

Hope it helps decide if this \n is needed or not.