longtabu 和 rotatebox 导致表格太宽

longtabu 和 rotatebox 导致表格太宽

我正在尝试制作一个固定的全宽表格,该表格可能跨越多个页面。我发现旋转标题会\rotatebox弄乱尺寸计算,但我找不到解决方法。\makebox例如被忽略。

测试用例:

\documentclass{article}
\usepackage{graphics}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{fancyhdr}    

\pagestyle{fancy}
\begin{document}
\begin{longtabu} to \linewidth{Xll}
some simple text & \rotatebox{90}{some really really really long text} & \rotatebox{90}{some really really really long text} \\
some simple text & \multicolumn{2}{l}{some much shorter text} \\
\end{longtabu}
\end{document}

答案1

\multicolumn没有被忽略,它只是不参与宽度计算。(通常有足够多的非跨越单元格,所以这不是问题,但在这里却存在问题)。

如果你把规则放入其中,会更容易看到:

\documentclass{article}
\usepackage{graphics}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{fancyhdr}    

\pagestyle{fancy}
\begin{document}
\begin{longtabu} to \linewidth{|X|l|l|}
some simple text & \rotatebox{90}{some really really really long text} & 
\rotatebox{90}{some really really really long text} \\
some simple text & \multicolumn{2}{l}{some much shorter text} \\
\end{longtabu}
\end{document}

因此,X除了旋转标题所需的空间之外,获取所有空间,然后放入多列,表格太宽

Overfull \hbox (72.6446pt too wide) in alignment at lines 12--12

在此处输入图片描述

如果第二列和第三列中有一些非跨越单元格,它们会更早被看到,并且该X列会分配较少的空间。

如果确实没有这样的条目,您可以在\kill未排版的行中添加一些:

\documentclass{article}
\usepackage{graphics}
\usepackage{longtable}
\usepackage{tabu}
\usepackage{fancyhdr}    

\pagestyle{fancy}
\begin{document}
\begin{longtabu} to \linewidth{|X|l|l|}
aaa&x\hspace{2.1cm}x&x\hspace{2.1cm}x\kill
some simple text & \rotatebox{90}{some really really really long text} &  
\rotatebox{90}{some really really really long text} \\
some simple text & \multicolumn{2}{l}{some much shorter text} \\
\end{longtabu}
\end{document}

在此处输入图片描述

相关内容