1
votes

I'm writing my thesis in Rmarkdown (specifically bookdown) and using knitr to compile it into a PDF.

When I knit it, everything works perfectly other than the tables and figures.

The tables (produced with kable) look almost perfect, but are wrapped as follows (where [table] is the table rendered correctly):

\begin{table}
\caption{(#tab:rchunk_label) table_caption}
[table]
\end{table}

Accordingly, the caption does not appear on the table. Furthermore, this causes the text alingment to change for the rest of the document. The issue goes away if I do not include a caption, but I believe a caption is supported for latex output.

The figures render correctly, other than the caption including the r chunk label in parenthesis before the actual caption.

If it is relevant, the "lot" (list of tables) function does not identify any tables in the document, whereas the "lof" (list of figures) function does.

So far, I've tried setting results to "asis", copying code into another document, and examining the raw latex output. The raw latex seems correct (no duplication of \begin{table} or anything).

1

1 Answers

1
votes

This problem is resolved by setting format to "pandoc" e.g.

someData %>%
  kable(caption = "a caption",
        format = "pandoc")

I'm not sure why this is, since more recent versions of kable are supposed to automatically select the format, but it appears to solve the problem.