[R] backslash in xtable (generate latex code from R)

Thierry Onkelinx th|erry@onke||nx @end|ng |rom |nbo@be
Fri Nov 6 13:42:32 CET 2020


You could use kable() from the knitr package.

kable(mytable, format = "latex", escape = FALSE)

\begin{tabular}{l}
\hline
$\beta_0$\\
\hline
aa\\
\hline
bb\\
\hline
cc$\alpha_1$\\
\hline
\end{tabular}


ir. Thierry Onkelinx
Statisticus / Statistician

Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team Biometrie & Kwaliteitszorg / Team Biometrics & Quality Assurance
thierry.onkelinx using inbo.be
Havenlaan 88 bus 73, 1000 Brussel
www.inbo.be

///////////////////////////////////////////////////////////////////////////////////////////
To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
///////////////////////////////////////////////////////////////////////////////////////////


<https://www.inbo.be>


Op vr 6 nov. 2020 om 13:30 schreef John <miaojpm using gmail.com>:

> I'd like to have $\alpha_1$ in my table, and the column name is $\beta_0$
> ####
> library(xtable)
> mytable <- data.frame(beta_0 = c("aa","bb","cc$\\alpha_1$"))
> colnames(mytable) <- "$\\beta_0$"
> print(xtable(mytable), include.rownames = F, sanitize.colnames.function =
> identity)
> ####
>
> No problem with \beta_0, but a problem with \alpha_1:
>
> \begin{table}[ht]
> \centering
> \begin{tabular}{l}
>   \hline
> $\beta_0$ \\
>   \hline
> aa \\
>   bb \\
>   cc\$$\backslash$alpha\_1\$ \\
>    \hline
> \end{tabular}
> \end{table}
>
> How may I fix the $\alpha_1$? Thanks!
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list