1
votes

Whenever I use captions in tables, like

kable(df[1:10, c(7,1:6)], caption = "This is a caption")

the tables and content in the pdf generated by knitr are pushed below the limits of the bottom margin, thus becoming unreadable. Sometimes entire sections are missing, hidden off margins.

Also, plots positions go crazy: they are printed anywhere but the right place in the pdf.

using results="asis" in chunk options doesn't help.

Using pander causes the same problems.

If I remove all table captions and use some \newpage in the .rmd, the pdf margins are fine.

Is there a safe way to use table captions?

The pdf in question is here: see page 14 for an entire section missing and table hiding in the bottom margins. Also, the plots are where they want, like if they had proper needs...

github repo

1
Posting a minimal reproducible example would help us to understand your problem.Martin Schmelzer
I'm trying really hard to reproduce the problem in a new file. I just can't. Maybe it's not the tables but the grids I'm using. I'll try removing the grids to see what happens.erickfis
It may be a similar issue to tex.stackexchange.com/q/276699/9128 To verify, you may try knitr::opts_knit$get(kable.force.latex = TRUE) before you call kabel() and see if it fixes the issue.Yihui Xie
@Yihui I've seen this thread before. It is the problem I'm facing. But the suggested fix, to use suppressfloats, doesn't work for me. I'll try your suggestion, thx!erickfis
@Yihui using opts_knit$set(kable.force.latex = TRUE) works, no bottom margins were broken, but now my tables are ugly as hell. Also, plots and tables are printed in a different location than the desired one.erickfis

1 Answers

0
votes

this is kind of a anti-climax,

but as it happens, this problem was being caused by chunks that printed var values to the document, something like:

```{r}
sampled.values <- sample(1:100, 10)
sampled.values
```

when rendered through render(), this code chunk prints the value of sampled.values and this ruins the pdf pagination.

That's it: all page bottom margins are ok now that I removed all those var calls.