当使用很长的多列项目时,页面会断掉

当使用很长的多列项目时,页面会断掉

我正在使用ltablexs \multicolumn。我的问题是,我必须在单个项目中引入大量文本\multicolumn,然后当它自动将表格拆分到两个不同的页面上时,它会在第一页的末尾留下大量空白。我想找到一个线索,\multicolumn当到达底部边距时自动拆分项目,而不是逐行拆分。以下是一个例子:

\begin{tabularx}{\linewidth}{| l | X | X | X | X | X | X | X |}
blabla & more blabla & \multicolumn{3}{c|}{merging cells} & \multicolumn{3}{c|}{more merging} \\
\multicolumn{8}{|p{\textwidth-2\tabcolsep-2\fboxrule}|}{a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, } \\
\hline
\multicolumn{8}{|p{\textwidth-2\tabcolsep-2\fboxrule}|}{a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, } \\
\hline
\multicolumn{8}{|p{\textwidth-2\tabcolsep-2\fboxrule}|}{a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, } \\
\hline
\multicolumn{8}{|p{\textwidth-2\tabcolsep-2\fboxrule}|}{a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, } \\
\hline
...
\multicolumn{8}{|p{\textwidth-2\tabcolsep-2\fboxrule}|}{a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, a very long text, } \\
\hline
\end{tabularx}

答案1

这里完全没有必要longtable/ltablex(也不需要使用 tabularx X 列)。如果使用tabularxtex,则需要花费大量精力重新设置表格并确定最佳列宽,但您事先知道跨越单元格是全宽,而单个单元格是全宽的八分之一(或至少是行宽的七分之一减去第一列中的最大条目)。因此,您可以告诉 TeX 这一点,并省去计算的麻烦。固定单元格宽度后,它们不再需要位于同一个表格中,因为它们无论如何都会对齐,因此您可以用普通文本替换跨越条目。如果您确实需要垂直规则,您可以使用mdframed可破坏的框架。

笔记

\textwidth-2\tabcolsep-2\fboxrule

不是正确的计算,因为规则宽度\arrayrulewidth不正确\fboxrule(当然它们可能具有相同的值)。

因此类似于:

在此处输入图片描述

\documentclass{article}

\addtolength\textheight{-30\baselineskip}
\addtolength\paperheight{-30\baselineskip}
\pdfpageheight\paperheight
\newenvironment{trow}
{\par
\begin{tabular}{|*8{p{\dimexpr(((\textwidth-\arrayrulewidth)/8)-2\tabcolsep-\arrayrulewidth)\relax}|}}
\hline}
{\\\hline\end{tabular}%
\par}
\begin{document}
\setlength\parindent{0pt}

\def\x{a very long text, a very long text, a very long text, a very long
text, a very long text, a very long text, a very long text, a very
long text, a very long text, a very long text, a very long text, a
very long text, a very long text, a very long text, a very long text,
a very long text, a very long text, a very long text, a very long
text, a very long text, a very long text, }

\x
\begin{trow}
red&yellow&blue&green&red&yellow&blue&green
\end{trow}
\begin{trow}
1&2&3&4&5&6&7&8
\end{trow}

\x
\begin{trow}
red&yellow&blue&green&red&yellow&blue&green
\end{trow}
\begin{trow}
1&2&3&4&5&6&7&8
\end{trow}

\x
\begin{trow}
red&yellow&blue&green&red&yellow&blue&green
\end{trow}
\begin{trow}
1&2&3&4&5&6&7&8
\end{trow}


\end{document}

相关内容