[英]How to print symbols with parenthesis in latex using xtable and Sweave
我正在嘗試使用xtable生成tex表。 在R中,該表包含:
>tvPre
p\\_1 p\\_2 p\\_3
FV "\\textuparrow M" "" "\\textuparrow R"
a "\\textuparrow WH" "" ""
b "\\textuparrow H" "" "\\textuparrow (H)"
c "\\textuparrow (WH)" "" "\\textuparrow (H)"
Oil "\\textuparrow W" "\\textuparrow R" "\\textdownarrow R"
如果我在控制台中使用身份驗證功能進行打印,則可以:指令:
print(xtable(tvPre), rotate.colnames=T,
sanitize.text.function = getOption("xtable.sanitize.text.function", function(x)x))
然后,我獲得:
& \begin{sideways} p\_1 \end{sideways} & \begin{sideways} p\_2\end{sideways} & \begin{sideways} p\_3 \end{sideways} \\
\hline
FV & \textuparrow M & & \textuparrow R \\
a & \textuparrow WH & & \\
b & \textuparrow H & & \textuparrow (H) \\
c & \textuparrow (WH) & & \textuparrow (H) \\
O & \textuparrow W & \textuparrow R & "\\textdownarrow R" \\
不過,當我將代碼放在Sweave文件( .Rnw
)中時,在.tex
我獲得了:
& \begin{sideways} p\_1 \end{sideways} & \begin{sideways} p\_2\end{sideways} & \begin{sideways} p\_3 \end{sideways} \\
\hline
FV & \textuparrow M & & \textuparrow R \\
a & \textuparrow W & & \\
b & H & & H \\
c & \textuparrow W & & H \\
O & \textuparrow W & \textuparrow R & \textdownarrow R \\
然后,所有括號都消失了,箭頭也消失了。 我也嘗試使用$\\\\uparrow$
,但仍然無法正常工作。 第三行第二列( "\\\\textuparrow WH"
)不帶"H"
打印,但在下一行" \\\\textuparrow H"
僅打印"H"
。 帶有括號的其余單元格在.tex
文件中沒有箭頭或括號的情況下打印。
我需要像在控制台中一樣在.tex中進行打印,有些提示?
好的,以下對我有用。 您的問題沒有說明您是否已加載textcomp軟件包-您需要這樣做。 同上側面包裝。 我也將sanitize.text.function更改為sanitize.text.function = function(x){x}
。
下面的腳本另存為.Rnw文件。
\documentclass{article}
\usepackage{textcomp}
\usepackage{rotating}
\begin{document}
\SweaveOpts{concordance=TRUE}
<<table, echo=FALSE, results=tex >>=
require(xtable)
tvPre <- as.data.frame(structure(list(`p\\\\_1` = c("\\textuparrow M", "\\textuparrow WH",
"\\textuparrow H", "\\textuparrow (WH)", "\\textuparrow W"),
`p\\\\_2` = c("", "", "", "", "\\textuparrow R"), `p\\\\_3` = c("\\textuparrow R",
"", "\\textuparrow (H)", "\\textuparrow (H)", "\\textdownarrow R"
)), .Names = c("p\\_1", "p\\_2", "p\\_3"), row.names = c("FV",
"a", "b", "c", "Oil"), class = "data.frame"))
print(xtable(tvPre), rotate.colnames = TRUE, sanitize.text.function = function(x){x})
@
\end{document}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.