В: Как я могу обрезать дополнительную длину горизонтального правила в таблицах LaTeX от R's xtable
?Обрезка дополнительного горизонтального правила в таблицах LaTeX из R's xtable
Я хотел бы сделать что-то подобное, как вы видите в моем R-коде ниже. Но этот код вызывает ошибки и не дает желаемого результата.
% table 1
\begin{table}[ht]
\centering
\begin{tabular}{@{}[email protected]{}}
\toprule
& a\_a & b\_b \\
\midrule
A & 0.35 & -1.05 \\
B & 0.64 & 0.92 \\
\bottomrule
\end{tabular}
\end{table}
% table 2
\begin{table}[ht]
\centering
\begin{tabular}{lrr}
\toprule
& a\_a & b\_b \\
\midrule
A & 0.36 & -1.05 \\
B & 0.64 & 0.92 \\
\bottomrule
\end{tabular}
\end{table}
# Begin R code
library(xtable)
library(stringr)
options(xtable.comment = FALSE)
set.seed(10)
mat <- matrix(rnorm(4), nrow=2)
rownames(mat) <- LETTERS[1:2]
colnames(mat) <- str_c(letters[1:2], "_", letters[1:2])
#mat.x <- xtable(mat, caption="My Caption!", align="lrr", digits=2) # No Error!
mat.x <- xtable(mat, align="@{}[email protected]{}", digits=2) # Error!
print(mat.x,
sanitize.text.function = function(x){x},
sanitize.colnames.function = function(x){str_replace_all(x, "_", "\\\\_")},
floating=T,
hline.after=NULL,
math.style.negative=F,
add.to.row=list(pos=list(-1,0,nrow(mat.x)),
command=c("\\toprule ", "\\midrule ", "\\bottomrule ")))
# Error in `align<-.xtable`(`*tmp*`, value = "@{}[email protected]{}") :
# "align" must have length equal to 3 (ncol(x) + 1)
# In addition: Warning message:
# In .alignStringToVector(value) : Nonstandard alignments in align string
не уверен, что вы хотите, но возьмите крошечный punt 'xtable (mat, align = c (" @ {} l "," r "," r @ {} "), цифры = 2)' – user20650
Пригвожден. Хотел бы я подумать об этом. Никогда не видел, чтобы фактический вектор символов передавался в аргумент align. Оно работает! – lowndrul