使用XeLaTeX生成含longtable的报表需三次编译,如何优化?
问题
使用XeLaTeX生成包含longtable的报表时,必须编译3次才能让表格布局显示正常,排查后发现问题和表格最后3列的multicolumn设置有关,有没有办法避免多次编译?
... \renewcommand{\arraystretch}{1.4} \arrayrulecolor{white} \setlength{\arrayrulewidth}{1mm} \footnotesize \begin{longtable}{ | >{\centering\arraybackslash}m{1.5cm}| >{\centering\arraybackslash}m{1.5cm}| >{\centering\arraybackslash}m{1.5cm}| >{\centering\arraybackslash}m{2.8cm}| >{\centering\arraybackslash}m{3.2cm}| >{\centering\arraybackslash}m{2.8cm}| >{\centering\arraybackslash}m{2cm}| >{\centering\arraybackslash}m{2.5cm}| >{\centering\arraybackslash}m{0.6cm}| >{\centering\arraybackslash}m{0.6cm}| >{\centering\arraybackslash}m{0.6cm} } % -------------------------- Table Header --------------------------------- \rowcolor{strapagBlue} \multicolumn{2}{|c|}{\textbf{Nom du site}} & \textbf{Cell-ID} &\textbf{Pays} & \textbf{Responsable} & \textbf{BTS-Type} & \textbf{TX-Puissance} & \textbf{Antenne} & \multicolumn{3}{c}{\textbf{Azimut}} \\ \rowcolor{strapagBlue} \textbf{Code} & \textbf{Cellule} & &\textbf{Canton} & & \textbf{Status} & \textbf{ERP} & \textbf{Fabricant} & \multicolumn{3}{c}{\textbf{El. Tilt}} \\ \rowcolor{strapagBlue} \textbf{X-Coord.} & \textbf{Y-Coord.} & \textbf{Altitude} & \textbf{Commune} & \textbf{Coordination} & \textbf{Polarisation} & \textbf{Nb. TRX} & \textbf{Haut. Ant.} & \multicolumn{3}{c}{\textbf{Tilt Mech.}} \\ \endhead % ---------------- Content --------------- \rowcolor{lightGray} \multicolumn{2}{|c|}{\textbf{XXXXX} } & \textbf{236 0321} & CH & XXXX& Normal BTS, MBSe3 & 38.0dBm & 3 x K741515 & 20° & 115° & 210° \\ ...


解决方案
- 给multicolumn指定固定宽度:当前最后3列的
multicolumn{3}{c}{...}未明确宽度,LaTeX需要多次编译计算实际尺寸。直接把宽度设为3列总宽度(3×0.6cm=1.8cm),比如改成\multicolumn{3}{|p{1.8cm}|}{\centering\textbf{Azimut}},用p列并手动居中,让LaTeX第一次编译就能确定宽度。 - 统一跨行列的宽度设置:表头3行的最后3列都用了
multicolumn,确保这些multicolumn的宽度完全一致,避免LaTeX反复协调不同行的宽度差异。比如把Azimut、El. Tilt、Tilt Mech.对应的multicolumn都设为相同的固定宽度。 - 提前定义全局格式:把
\arraystretch、arrayrulecolor这些格式设置放在文档开头或longtable之前,避免LaTeX因格式变更重新计算行高和布局,减少编译次数。 - 改用tabularx结合longtable(可选):如果不想手动计算宽度,可使用
longtable搭配tabularx,用X列自动分配宽度,但注意兼容性,这种方法最多只需要2次编译。
内容的提问来源于stack exchange,提问作者Riuss
相关产品推荐
相关产品推荐

