[R] backslash in xtable (generate latex code from R)
m@rc_@chw@rtz @end|ng |rom me@com
Fri Nov 6 14:04:28 CET 2020
It looks like xtable is "sanitizing" special characters in the LaTeX output by default, by adding a double backslash, so that LaTeX will process the characters as literals, rather than specials. It is not parsing the boundary '$' characters to define insertion of math symbols inside text mode.
You have 'sanitize.colnames.function = identity', which is why the column name is output 'as is'.
You would seem to need to do the same thing for the text content within the table content:
> print(xtable(mytable), include.rownames = F,
sanitize.colnames.function = identity,
sanitize.text.function = identity)
% latex table generated in R 4.0.3 by xtable 1.8-4 package
% Fri Nov 6 07:54:51 2020
> On Nov 6, 2020, at 7:39 AM, John <miaojpm using gmail.com> wrote:
> I'd like to have $\alpha_1$ in my table, and the column name is $\beta_0$
> mytable <- data.frame(beta_0 = c("aa","bb","cc$\\alpha_1$"))
> colnames(mytable) <- "$\\beta_0$"
> print(xtable(mytable), include.rownames = F, sanitize.colnames.function =
> No problem with \beta_0, but a problem with \alpha_1:
> $\beta_0$ \\
> aa \\
> bb \\
> cc\$$\backslash$alpha\_1\$ \\
> How may I fix the $\alpha_1$? Thanks!
More information about the R-help