gpt4 book ai didi

r - 如何将长 LaTeX 表格拆分成相邻的列?

转载 作者:行者123 更新时间:2023-12-04 15:16:39 28 4
gpt4 key购买 nike

我有一张长 table ;

long_table <- structure(list(species = c("ABIBAL", "ACEPEN", "ACERUB", "ACESAC", 
"ACESPI", "ARANUD", "ARITRI", "ATHANG", "BETALL", "CARARC", "CARINT",
"CINLAT", "CLIBOR", "DENPUN", "DRYCAM", "DRYINT", "FAGGRA", "FRAAME",
"HUPLUC", "LONCAN", "MAICAN", "MAIRAC", "MEDVIR", "NABSPP", "OCLACU",
"OXAMON", "PARNOV", "PHECON", "PICRUB", "RUBIDA", "SAMRAC", "STRAMP",
"TIACOR", "TRIBOR", "TRIERE", "TRIUND", "TSUCAN", "UVUSES", "VIBLAN",
"VIOBLA", "VIOROT"), all_3 = c(0.805, 0.84, 0.682, 0.764, 0.783,
0.828, 0.799, 0.765, 0.704, 0.782, 0.771, 0.799, 0.733, 0.694,
0.658, 0.82, 0.821, 0.766, 0.742, 0.721, 0.793, 0.782, 0.755,
0.738, 0.62, 0.753, 0.711, 0.736, 0.657, 0.694, 0.769, 0.664,
0.77, 0.735, 0.83, 0.709, 0.785, 0.749, 0.827, 0.744, 0.799),
topo_spectral_3 = c(0.729, 0.729, 0.592, 0.762, 0.668, 0.735,
0.736, 0.758, 0.626, 0.782, 0.589, 0.649, 0.753, 0.647, 0.633,
0.833, 0.821, 0.717, 0.667, 0.591, 0.76, 0.747, 0.699, 0.652,
0.522, 0.531, 0.696, 0.708, 0.704, 0.675, 0.739, 0.673, 0.678,
0.697, 0.705, 0.683, 0.717, 0.748, 0.725, 0.676, 0.793),
default = c(0.701, 0.553, 0.628, 0.605, 0.565, 0, 0.601,
0.574, 0, 0.5, 0, 0.566, 0, 0.544, 0.58, 0.582, 0.614, 0.5,
0.649, 0, 0, 0.465, 0.585, 0.528, 0, 0.619, 0.486, 0.536,
0.49, 0.586, 0.704, 0, 0.564, 0, 0.528, 0.556, 0, 0.497,
0, 0.533, 0.586)), row.names = c(NA, -41L), class = "data.frame")

我正在为发布做准备,希望整个表格无需滚动即可查看。对我来说最明显的解决方案是将列加倍,从而将长度减半。

我在 LaTex 社区 ( https://tex.stackexchange.com/questions/134381/dealing-with-very-long-table-split-into-columns ) 中看到了此类讨论,但没有看到有关如何使用 R 执行此操作的文档。

图片来自以上链接;

enter image description here

如何使用 R 制作如上图所示的双倍宽度的出版质量表?

最佳答案

使用 xtable 很容易:

xtable::xtable(long_table)

此代码将 LaTeX 代码打印到控制台,您可以将其复制到 Rmarkdown 文件中。不要将其放入代码垃圾中,将其作为普通文本放入。然后只需应用 instructions你分享了你的问题,并插入了一些带点的线,使面板的长度相等。

---
output: pdf_document
classoption:
- a4paper
- landscape
---
<!-- suppress page numbers -->
\pagenumbering{gobble}

\begin{table}[ht]
\centering
\begin{tabular}{rlrrr}
\hline
& species & all\_3 & topo\_spectral\_3 & default \\
\hline
1 & ABIBAL & 0.80 & 0.73 & 0.70 \\
2 & ACEPEN & 0.84 & 0.73 & 0.55 \\
3 & ACERUB & 0.68 & 0.59 & 0.63 \\
4 & ACESAC & 0.76 & 0.76 & 0.60 \\
5 & ACESPI & 0.78 & 0.67 & 0.56 \\
6 & ARANUD & 0.83 & 0.73 & 0.00 \\
7 & ARITRI & 0.80 & 0.74 & 0.60 \\
8 & ATHANG & 0.76 & 0.76 & 0.57 \\
9 & BETALL & 0.70 & 0.63 & 0.00 \\
10 & CARARC & 0.78 & 0.78 & 0.50 \\
11 & CARINT & 0.77 & 0.59 & 0.00 \\
12 & CINLAT & 0.80 & 0.65 & 0.57 \\
13 & CLIBOR & 0.73 & 0.75 & 0.00 \\
14 & DENPUN & 0.69 & 0.65 & 0.54 \\
15 & DRYCAM & 0.66 & 0.63 & 0.58 \\
16 & DRYINT & 0.82 & 0.83 & 0.58 \\
17 & FAGGRA & 0.82 & 0.82 & 0.61 \\
18 & FRAAME & 0.77 & 0.72 & 0.50 \\
19 & HUPLUC & 0.74 & 0.67 & 0.65 \\
20 & LONCAN & 0.72 & 0.59 & 0.00 \\
. & . & . & . & . \\
. & . & . & . & . \\
. & . & . & . & . \\
\hline
\end{tabular}
\begin{tabular}{rlrrr}
\hline
& species & all\_3 & topo\_spectral\_3 & default \\
\hline
. & . & . & . & . \\
. & . & . & . & . \\
21 & MAICAN & 0.79 & 0.76 & 0.00 \\
22 & MAIRAC & 0.78 & 0.75 & 0.46 \\
23 & MEDVIR & 0.76 & 0.70 & 0.58 \\
24 & NABSPP & 0.74 & 0.65 & 0.53 \\
25 & OCLACU & 0.62 & 0.52 & 0.00 \\
26 & OXAMON & 0.75 & 0.53 & 0.62 \\
27 & PARNOV & 0.71 & 0.70 & 0.49 \\
28 & PHECON & 0.74 & 0.71 & 0.54 \\
29 & PICRUB & 0.66 & 0.70 & 0.49 \\
30 & RUBIDA & 0.69 & 0.68 & 0.59 \\
31 & SAMRAC & 0.77 & 0.74 & 0.70 \\
32 & STRAMP & 0.66 & 0.67 & 0.00 \\
33 & TIACOR & 0.77 & 0.68 & 0.56 \\
34 & TRIBOR & 0.73 & 0.70 & 0.00 \\
35 & TRIERE & 0.83 & 0.70 & 0.53 \\
36 & TRIUND & 0.71 & 0.68 & 0.56 \\
37 & TSUCAN & 0.78 & 0.72 & 0.00 \\
38 & UVUSES & 0.75 & 0.75 & 0.50 \\
39 & VIBLAN & 0.83 & 0.72 & 0.00 \\
40 & VIOBLA & 0.74 & 0.68 & 0.53 \\
41 & VIOROT & 0.80 & 0.79 & 0.59 \\
\hline
\end{tabular}
\end{table}

enter image description here

您可能需要查看 booktabs LaTeX package您可以使用 toprule, midrule, bottomrule 绘制更好的线条。

关于r - 如何将长 LaTeX 表格拆分成相邻的列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64213097/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com