![如何方便处理双列文档中的全宽多页表格?](https://linux22.com/image/381493/%E5%A6%82%E4%BD%95%E6%96%B9%E4%BE%BF%E5%A4%84%E7%90%86%E5%8F%8C%E5%88%97%E6%96%87%E6%A1%A3%E4%B8%AD%E7%9A%84%E5%85%A8%E5%AE%BD%E5%A4%9A%E9%A1%B5%E8%A1%A8%E6%A0%BC%EF%BC%9F.png)
最近,我试图将一个包含大量文本的长多列表格放入一个双列单文件文档中。该文档tabularx
在双列模式下大量使用单列,而我的长表则处于单列模式。我费了好大劲才让多页表方便地与tabularx
最多页面宽度的列格式配合使用。
至于便利/自动化部分(感谢很好的概述), 我知道
tabularx
,非常适合列格式化但不适用于多页表ltablex
,非常适合tabularx
与longtable
但与双栏文档匹配不佳(至少我还没能设法避开ltablex
对包所做的更改tabularx
)xtab
(增强supertabular
),超棒的功能但不支持tabularx
-style 列格式(至少我还没有做到)tabulary
,可以很好地自动设置列格式但是不是正确的事情制作多页表
我在多页表上找到了一些答案tabularx
(例如这里,这里tabulary
) 以及使用(的答案这里),并没有完全实现我的意图。
以下 MWE 的使用ltablex
几乎满足了我的要求:
\documentclass[twocolumn]{article}
\usepackage{lipsum}
% \usepackage{tabularx} % works for 1st table only
\usepackage{ltablex} % works for 2nd table only
\begin{document}
\title{Title}
\author{Author}
\maketitle
\lipsum[1-4]
\begin{table}
\caption{A small table in twocolumn mode}
\begin{tabularx}{\columnwidth}{lllXX}
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} & \textbf{C5} \\
A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. \\
A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though.
\end{tabularx}
\end{table}
\newpage
\onecolumn
\begin{tabularx}{\linewidth}{l>{\hsize.2\hsize}XXX}
\caption{Full-width multi-page table in one-column mode}\\
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
\endfirsthead
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
\endhead
\multicolumn{4}{r}{{Continued on next page}} \\
\endfoot
\multicolumn{4}{r}{{End}} \\
\endlastfoot
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11]
\end{tabularx}
\newpage
\twocolumn
\lipsum[10-14]
\end{document}
MWE 可以与第一个表和tabularx
或第二个表和一起使用ltablex
。但是,使用ltablex
(使用longtable
),我得到:
Package longtable Error: longtable not in 1-column mode.
另外,我了解了这个ltxtable
软件包,但它需要拆分文件。我能ltablex
更好地处理双列模式吗?还是必须切换到ltxtable
?
谢谢你!
答案1
根据David的建议,我将我的MWE修改为:
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{tabularx} % works for 1st table only
\usepackage{ltxtable} % works for 2nd table only
\begin{document}
\title{Title}
\author{Author}
\maketitle
\lipsum[1-4]
\begin{table}
\caption{A small table in twocolumn mode}
\begin{tabularx}{\columnwidth}{lllXX}
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} & \textbf{C5} \\
A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. \\
A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though.
\end{tabularx}
\end{table}
\newpage
\onecolumn
\LTXtable{\linewidth}{table.tex}
\newpage
\twocolumn
\lipsum[10-14]
\end{document}
表格位于一个额外的文件中table.tex
:
\begin{longtable}{l>{\hsize.2\hsize}XXX}
\caption{Full-width multi-page table in one-column mode}\\
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
\endfirsthead
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
\endhead
\multicolumn{4}{r}{{Continued on next page}} \\
\endfoot
\multicolumn{4}{r}{{End}} \\
\endlastfoot
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11]
\end{longtable}
如果我们接受将文档分成两个文件,这是一个不错的解决方案。
答案2
有一个最近的包xltabular
可以将所有代码放在一个文件中,摆脱ltablex
双列模式(浮动)的干扰,同时引入一些便利longtable
:
\documentclass[twocolumn]{article}
\usepackage{lipsum}
\usepackage{tabularx} % works for 1st table only
\usepackage{xltabular} % works for 2nd table only
\begin{document}
\title{Title}
\author{Author}
\maketitle
\lipsum[1-4]
\begin{table}
\caption{A small table in twocolumn mode}
\begin{tabularx}{\columnwidth}{lllXX}
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} & \textbf{C5} \\
A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though. \\
A & 1 & a & Quite a bit of text here as well, though. & Quite a bit of text here as well, though.
\end{tabularx}
\end{table}
\newpage
\onecolumn
\begin{xltabular}{\linewidth}{l>{\hsize.2\hsize}XXX}
\caption{Full-width multi-page table in one-column mode}\\
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
\endfirsthead
\textbf{C1} & \textbf{C2} & \textbf{C3} & \textbf{C4} \\
\endhead
\multicolumn{4}{r}{{Continued on next page}} \\
\endfoot
\multicolumn{4}{r}{{End}} \\
\endlastfoot
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11] \\
Text & Some other text here & \lipsum[11] & \lipsum[11]
\end{xltabular}
\newpage
\twocolumn
\lipsum[10-14]
\end{document}
感谢 David Carlisle 向我推荐了该软件包。