有没有办法让 TeX xtable 源代码结果格式正确,更易读?例如:
library(xtable)
## Load example dataset
data(tli)
print(tli.table)
给出
\begin{table}[ht]
\centering
\begin{tabular}{rrlllr}
\hline
& grade & sex & disadvg & ethnicty & tlimth \\
\hline
1 & 6 & M & YES & HISPANIC & 43 \\
2 & 7.0 & M & NO & BLACK & 88.0 \\
3 & 5.00 & F & YES & HISPANIC & 34.00 \\
4 & 3.000 & M & YES & HISPANIC & 65.000 \\
5 & 8.0000 & M & YES & WHITE & 75.0000 \\
6 & 5 & M & NO & BLACK & 74 \\
7 & 8.0 & F & YES & HISPANIC & 72.0 \\
8 & 4.00 & M & YES & BLACK & 79.00 \\
9 & 6.000 & M & NO & WHITE & 88.000 \\
10 & 7.0000 & M & YES & HISPANIC & 87.0000 \\
11 & 3 & M & NO & WHITE & 79 \\
12 & 6.0 & F & NO & WHITE & 84.0 \\
13 & 8.00 & M & NO & WHITE & 90.00 \\
14 & 5.000 & M & NO & WHITE & 73.000 \\
15 & 8.0000 & F & NO & WHITE & 72.0000 \\
16 & 6 & F & NO & BLACK & 82 \\
17 & 4.0 & M & NO & WHITE & 69.0 \\
18 & 3.00 & F & YES & HISPANIC & 17.00 \\
19 & 3.000 & M & NO & HISPANIC & 37.000 \\
20 & 5.0000 & M & NO & WHITE & 70.0000 \\
\hline
\end{tabular}
\end{table}
如果我用类似的东西http://www.tablesgenerator.com/它给出了以下内容(列间距更均匀,因此在 TeX 中更易读)
\begin{table}[]
\centering
\begin{tabular}{rrlllr}
\hline
& grade & sex & disadvg & ethnicty & tlimth \\ \hline
1 & 6 & M & YES & HISPANIC & 43 \\
2 & 7.0 & M & NO & BLACK & 88.0 \\
3 & 5.00 & F & YES & HISPANIC & 34.00 \\
4 & 3.000 & M & YES & HISPANIC & 65.000 \\
5 & 8.0000 & M & YES & WHITE & 75.0000 \\
6 & 5 & M & NO & BLACK & 74 \\
7 & 8.0 & F & YES & HISPANIC & 72.0 \\
8 & 4.00 & M & YES & BLACK & 79.00 \\
9 & 6.000 & M & NO & WHITE & 88.000 \\
10 & 7.0000 & M & YES & HISPANIC & 87.0000 \\
11 & 3 & M & NO & WHITE & 79 \\
12 & 6.0 & F & NO & WHITE & 84.0 \\
13 & 8.00 & M & NO & WHITE & 90.00 \\
14 & 5.000 & M & NO & WHITE & 73.000 \\
15 & 8.0000 & F & NO & WHITE & 72.0000 \\
16 & 6 & F & NO & BLACK & 82 \\
17 & 4.0 & M & NO & WHITE & 69.0 \\
18 & 3.00 & F & YES & HISPANIC & 17.00 \\
19 & 3.000 & M & NO & HISPANIC & 37.000 \\
20 & 5.0000 & M & NO & WHITE & 70.0000 \\ \hline
\end{tabular}
\end{table}
谢谢
答案1
只要tabular
环境中的输入材料不是太难辨认,我几乎不费吹灰之力就能漂亮地打印输入材料。相反,我会花很大力气让排版输出为了让你的读者在视觉上更有吸引力,可以这样说:
\documentclass{memoir}
\usepackage{siunitx,array,booktabs}
\newcolumntype{T}[1]{S[table-format=#1]}
\newcolumntype{L}{>{\scshape}l}
\begin{document}
\begin{table}
\centering
\begin{tabular}{@{} T{2.0} T{1.4} LLL T{2.4} @{}}
\toprule
& {\scshape grade} & sex & disadvg & ethnicty & {\scshape tlimth} \\
\midrule
1 & 6 & m & yes & hispanic & 43 \\
2 & 7.0 & m & no & black & 88.0 \\
3 & 5.00 & f & yes & hispanic & 34.00 \\
4 & 3.000 & m & yes & hispanic & 65.000 \\
5 & 8.0000 & m & yes & white & 75.0000 \\
6 & 5 & m & no & black & 74 \\
7 & 8.0 & f & yes & hispanic & 72.0 \\
8 & 4.00 & m & yes & black & 79.00 \\
9 & 6.000 & m & no & white & 88.000 \\
10 & 7.0000 & m & yes & hispanic & 87.0000 \\
11 & 3 & m & no & white & 79 \\
12 & 6.0 & f & no & white & 84.0 \\
13 & 8.00 & m & no & white & 90.00 \\
14 & 5.000 & m & no & white & 73.000 \\
15 & 8.0000 & f & no & white & 72.0000 \\
16 & 6 & f & no & black & 82 \\
17 & 4.0 & m & no & white & 69.0 \\
18 & 3.00 & f & yes & hispanic & 17.00 \\
19 & 3.000 & m & no & hispanic & 37.000 \\
20 & 5.0000 & m & no & white & 70.0000 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}