问题描述
我有一个包含以下列的表格:
I have a table that includes the following column:
mytable <- data.frame(beta_0 = c(1,2,3)
我想要做的是在乳胶标记中输出一个带有列标题的表格,例如$eta_0$
What I want to do is output a table with a column header in latex markup, e.g. $eta_0$
但是,我似乎不知道如何使用 print.xtable
输出$eta_0$":
However, I can not seem to figure out how to output the "$eta_0$" using print.xtable
:
colnames(mytable) <- "$eta_0$"
library(xtable)
print(xtable(mytable), include.rownames = F)
返回一个列标题
eta\_0$
而不是
$eta_0$
我认为答案是 print.xtable
的sanitize.colnames.function"参数,但我不清楚如何使用它,以及 ?print.xtable
没有提供示例.
I presume that the answer is the "sanitize.colnames.function" argument to print.xtable
, but it is not obvious to me how to use this, and ?print.xtable
provides no examples.
具体来说,我想输出一个像这样的乳胶表:
Specifically, I would like to output a latex table like:
egin{table}[ht]
egin{center}
egin{tabular}{r}
hline
$eta_0$ \
hline
1.00 \
2.00 \
3.00 \
hline
end{tabular}
end{center}
end{table}
推荐答案
这里有两个问题;首先,您需要一个双反斜杠,否则它会将其视为控制序列.其次,默认情况下,xtable
会清理文本,使其不会破坏 LaTeX.使用 sanitize.
参数之一来控制它;要不进行消毒,请将其传递给身份函数.
Two issues here; first, you need a double backslash as otherwise it treats it as a control sequence. Second, by default, xtable
sanitizes text so that it won't break LaTeX. Use one of the sanitize.
parameters to control this; to do no sanitizing, pass it the identity function.
colnames(mytable) <- "$\beta_0$"
print(xtable(mytable), include.rownames = F, sanitize.colnames.function = identity)
这篇关于在 xtable 中处理 Latex 反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!