假设某个表格太宽,无法在一页上显示。在这种情况下,您可以做的是将表格打印到多页上,以便可以并排查看,方法是使用多个表格环境并用分页符将它们分隔开。
鉴于这些列定义:
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
2 页宽表格的表格代码类似于:
\begin{longtable}{|L{80pt}|L{80pt}|}
\hline
header 1 & header 2 \\
\hline
value 11 this is a much longer value which causes issues by overflowing into another line and misaligning this table with the other table & value 12 \\
value 21 & value 22 \\
\hline
\end{longtable}
\pagebreak
\begin{longtable}{|L{80pt}|L{80pt}|}
\hline
header 3 & header 4 \\
\hline
value 13 & value 14 \\
value 23 & value 24 \\
\hline
\end{longtable}
请注意,这些值是可变的。实际上,每个单元格内都可以包含“任何相当长的文本”。
只要所有值的集合中没有跨多行的值(例如没有带换行符的单元格),此方法便可行并对齐。但是,一旦有带换行符的单元格,这些换行符将仅出现在其各自的表格中。
如何对齐表格?例如,在表格 i 中,第 j 列将其列高设置为至少为第 j 列所有表格的列高中的最大值。
答案1
您可以创建一个两页的表格,然后使用 一次显示一半\adjustbox
。找出间隙的位置可能会带来问题。我还添加了一些代码,以便将两页放在偶数页上。
顺便说一句,我不熟悉 L 型列,因此使用 p 代替。
\documentclass{article}
\usepackage{adjustbox}
\usepackage{afterpage}
\usepackage{lipsum}% MWE only
\newsavebox{\twopage}
\newcommand{\evenpage}{\ifodd\value{page}\afterpage{\evenpage}%
\else
\hspace*{\fill}\adjustbox{Clip=0pt 0pt {0.5\width} 0pt}{\usebox{\twopage}}
\newpage
\adjustbox{Clip={0.5\width} 0pt 0pt 0pt}{\usebox{\twopage}}
\newpage
\fi}
\begin{document}
\savebox{\twopage}{\begin{tabular}
{|p{80pt}|p{80pt}|@{\hspace{2\tabcolsep}}|p{80pt}|p{80pt}|}
\hline
header 1 & header 2 & header 3 & header 4 \\
\hline
value 11 & value 12 & value 13 & value 14 \\
value 21 & value 22 & value 23 & value 24 \\
\hline
\end{tabular}}%
\evenpage
\lipsum[1-8]
\end{document}
我想尝试使其更像一个表格,包括分为两页的标题。
\documentclass{article}
\usepackage{adjustbox}
\usepackage{afterpage}
\usepackage{lipsum}% MWE only
\usepackage{blindtext}% MWE only
%\usepackage{showframe}% debugging tool
\usepackage{caption}
\newsavebox{\twopage}
\newsavebox{\twopagecaption}
\newlength{\twopagecaptionht}
\makeatletter
\@ifpackageloaded{caption}%
{\newcommand\makecaption[2]{%
{\captionlabelfont #1}%
{\caption@iflf\captionlabelfont\relax\caption@lsep}%
{\captiontextfont
\caption@ifstrut
{\vrule\@height\ht\strutbox\@width\z@}%
{}%
\nobreak\hskip\z@skip % enable hyphenation
\caption@tfmt{#2}%
\caption@ifstrut
{\ifhmode\@finalstrut\strutbox\fi}%
{}%
}%
}}%
{}
\newcommand{\splitcaption}[2][\empty]% #1 = short caption (optional), #2 = caption
{\setbox\twopagecaption=\vbox{\parindent=0pt
\refstepcounter{table}%
\ifx\empty#1\relax
\addcontentsline{lot}{table}%
{\protect\numberline{\thetable}{\ignorespaces #2}}%
\else
\addcontentsline{lot}{table}%
{\protect\numberline{\thetable}{\ignorespaces #1}}%
\fi
\let\vskip=\@gobble
\@ifundefined{makecaption}{}{\let\@makecaption=\makecaption}%
\@makecaption{\fnum@table}{\ignorespaces #2}%
\par}}
\makeatother
\newcommand{\evenpage}{\clearpage
\ifodd\value{page}\afterpage{\evenpage}%
\else
\noindent\begin{minipage}[c][\textheight][c]{\textwidth}
\hspace*{\fill}\adjustbox{Clip=0pt 0pt {0.5\width} 0pt}{\usebox{\twopage}}\par
\vskip\abovecaptionskip
\twopagecaptionht=\dimexpr \ht\twopagecaption + \dp\twopagecaption\relax
\dimen0=\dimexpr 0.5\twopagecaptionht + 0.5\baselineskip\relax
\setbox0=\vsplit\twopagecaption to \dimen0
\dimen0=\dimexpr \ht\twopagecaption + \dp\twopagecaption\relax
\advance\twopagecaptionht by -\dimen0
\ifdim\twopagecaptionht<\dimen0 \twopagecaptionht=\dimen0\fi
\vbox to \twopagecaptionht {\unvbox0\vfill}%
\global\twopagecaptionht=\twopagecaptionht
\end{minipage}\par
\noindent\begin{minipage}[c][\textheight][c]{\textwidth}
\adjustbox{Clip={0.5\width} 0pt 0pt 0pt}{\usebox{\twopage}}\par
\vskip\abovecaptionskip
\vbox to \twopagecaptionht {\unvbox\twopagecaption\vfill}%
\end{minipage}%
\fi}
\begin{document}
\listoftables
\savebox{\twopage}{\begin{tabular}
{|p{80pt}|p{80pt}|@{\hspace{2\tabcolsep}}|p{80pt}|p{80pt}|}
\hline
header 1 & header 2 & header 3 & header 4 \\
\hline
value 11 & value 12 & value 13 & value 14 \\
value 21 & value 22 & value 23 & value 24 \\
\hline
\end{tabular}}%
\splitcaption[short caption]{\blindtext}%
\afterpage{\evenpage}
\lipsum[1-8]
\end{document}