How to print a literal "%" at the beginning of a line?

How does one print a literal '%' sign in a knitr to pdf kable? I had a table with a list of row.names, one of which was "% change." I spent a long time confused over why this line in the table kept getting left out until I realized that when the table was rendered to Latex, the "%" was recognized as a comment indicator so that the line was not printed. In Latex, supposedly one can escape this treatment by prepending the "%" with a backslash "%". But neither a single nor a double backslash worked to restore that line of the table. Eventually I solved this by simply changing "% change" to "Percent change". But there must be a straight forward way to render a text '%' in a kable line. Thanks in advance for any suggestions.

In a vanilla Rmd file, it renders as the first character of a column heading.

title: "kabel % demo"
author: "Richard Careaga"
date: 2021-12-26
output: pdf_document

```{r setup, include=FALSE}
dat <- mtcars[1:5, 1:6]
colnames(dat)[1] <- "% fuel"

R Markdown

kable(dat) %>% kable_styling()

As the first line of text, it also works.


Where it *would not work* is within a $\LaTeX$ block, such as

\item % is the first character of this line

because in this context % opens a comment. It needs to be slash escaped.

\item \% is the first character of this line

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.