kableExtra icon indicating copy to clipboard operation
kableExtra copied to clipboard

Wide tables in LaTeX - suggested additional options.

Open donnekgit opened this issue 4 years ago • 0 comments

你好!I've been looking at kableExtra this last week for a project. It's a very nice package - thanks for making it. I noticed an issue with wide tables in LaTeX that I think could be fixed pretty easily. R isn't my strong point, so I thought I'd just log it here instead of blundering around in the files.

Basically, when landscape() is used to orient a wide table on the page (p26 of the LaTeX vignette), it ruins the flow of the text, because it is not a float. It leaves white space from where the table is inserted to where it actually appears. This can be fixed by wrapping the table call in \afterpage{ ... }. If the generation routine for the table when landscape() is used could add \afterpage{ above the output, and } below it, this would solve the problem. Users would then need to ensure that the pdflscape and afterpage packages were loaded in their LaTeX document.

Incidentally, the tex output gets printed \begin{landscape}\begin{table}, so there should probably be a newline in there.

An alternative is to load the package rotating, and use \begin{sidewaystable} ... \end{sidewaystable}. This does not maintain the reading orientation of the pdf, since it's printed sideways, but some may prefer it. Currently, this can be done by direct editing of the generated tex file, but it would be better (eg in the case of an automated pipeline) if this could be done automatically. Currently, there is the switch longtable=TRUE (p28 of the LaTeX vignette), which swaps in longtable to replace table, but this is not possible with sidewaystable. One option might be to provide a switch along the lines of table_environment=..., which would simply swap in the name of the desired table environment to the \begin{table} and \end{table} statements. This would allow any other table environment to be used.

I would also LOVE the option of putting the caption to tables BELOW the table (which is, I would say, the standard in - the suggested workaround of running things through xtable first (p29 of the LaTeX vignette) is not ideal, because it introduces an additional package with its own idiosyncracies. However, I accept that providing a "below-table" option may be more difficult.

donnekgit avatar Nov 21 '20 11:11 donnekgit