如何方便处理双列文档中的全宽多页表格?

如何方便处理双列文档中的全宽多页表格?

最近,我试图将一个包含大量文本的长多列表格放入一个双列单文件文档中。该文档tabularx在双列模式下大量使用单列,而我的长表则处于单列模式。我费了好大劲才让多页表方便地与tabularx最多页面宽度的列格式配合使用。

至于便利/自动化部分(感谢很好的概述), 我知道

  • tabularx,非常适合列格式化不适用于多页表
  • ltablex,非常适合tabularxlongtable 与双栏文档匹配不佳(至少我还没能设法避开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 向我推荐了该软件包。

相关内容