4

When I create a table using the knitr::kable function within a RNW file, the text color of the table items in the PDF appears to be grey.

I would like to change this to black. How can I do this?

CL.
  • 14,577
  • 5
  • 46
  • 73
der_grund
  • 1,898
  • 20
  • 36

1 Answers1

5
\documentclass{article}
\begin{document}
<<>>=
  knitr::kable(cars[1:10,]) # grey
@

<<results="asis">>=
  knitr::kable(cars[1:10,]) # black
@
\end{document}

By default, the output of kable will be wrapped in a knitrout environment where the text color (fgcolor) is set to grey (rgb: 0.345, 0.345, 0.345). This is what happens in the first chunk.

With results="asis", the output is not wrapped in any enclosing environment, leaving the text color unchanged (black).

CL.
  • 14,577
  • 5
  • 46
  • 73
  • 1
    Thank you for this. Is there a way to change that default effect to something else like black instead of changing the result to asis? Not sure why the default would be to change the color of your stuff. – Sahir Moosvi Dec 18 '18 at 17:44