我有一个 PDF 文件,其中的表格打印在两页上。表格可以容纳 9 列(一个列标题和 8 个数据列)。第一页正好包含 9 列。第二页只有一个列标题和 3 个数据列。第二页上的三个数据列占据了整个表格宽度。
我的问题是如何打印并排的三个数据列,以便它们能够对齐第一页上的前三个数据列?
以下是 MWE:
%!TEX TS-Program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{graphicx,booktabs,fancyhdr}
\usepackage{ctable}
\usepackage{url}
\usepackage{array,booktabs,makecell}
\usepackage{longtable}
\usepackage{tabularx}
%\usepackage{tabular}
\usepackage[margin=2.5cm]{geometry}
\setlength\parindent{0pt}
\newcommand{\sectionheader}[1] {
\textbf{#1}
\rule{\textwidth}{6pt}
}
\newcommand\zcolumn[1]{%
{\begin{tabular}{c}#1\end{tabular}\linebreak[0]}}
\setlength{\heavyrulewidth}{0.12em}
\pagenumbering{arabic}
\pagestyle{fancy}
\lhead{Report Name: SomeOne}
\rhead{\thepage}
\cfoot{}
\begin{document}
\sectionheader{Data}
\begin{tabularx}{\textwidth}{l*{8}X}
\textbf{Catagory1}
& {6/25/16} & {6/26/16} & {6/27/16} & {6/28/16} & {6/29/16} & {6/30/16} & {7/1/16} & {7/2/16}\\
\addlinespace
{SubCatagory1}
& - & - & - & - & - & - & - & -
\\\addlinespace{SubCatagory1}
& - & - & - & - & - & - & - & -
\\\addlinespace
\hline
\textbf{Catagory2}
& {6/25/16} & {6/26/16} & {6/27/16} & {6/28/16} & {6/29/16} & {6/30/16} & {7/1/16} & {7/2/16}\\
\addlinespace
{SubCatagory1}
& - & - & - & - & - & - & - & -
\\\addlinespace
\hline
\textbf{Catagory3}
& {6/25/16} & {6/26/16} & {6/27/16} & {6/28/16} & {6/29/16} & {6/30/16} & {7/1/16} & {7/2/16}\\
\addlinespace
{SubCatagory1}
& - & - & - & - & - & - & - & -
\\\addlinespace{SubCatagory2}
& - & - & - & - & - & - & - & -
\\\addlinespace
\hline
\textbf{Catagory4}
& {6/25/16} & {6/26/16} & {6/27/16} & {6/28/16} & {6/29/16} & {6/30/16} & {7/1/16} & {7/2/16}\\
\addlinespace
{SubCatagory1}
& - & - & - & - & - & - & - & -
\\\addlinespace{SubCatagory2}
& - & - & - & - & - & - & - & -
\\\addlinespace{SubCatagory3}
& - & - & - & - & - & - & - & -
\\\addlinespace{SubCatagory4}
& - & - & - & - & - & - & - & -
\\\addlinespace
\hline
\textbf{Catagory5}
& {6/25/16} & {6/26/16} & {6/27/16} & {6/28/16} & {6/29/16} & {6/30/16} & {7/1/16} & {7/2/16}\\
\addlinespace
{SubCatagory1}
& - & - & - & - & 1 & - & - & -
\\\addlinespace{SubCatagory2}
& - & - & - & - & - & 1 & - & -
\\\addlinespace{SubCatagory3}
& - & - & - & - & - & - & 1 & -
\\\addlinespace{SubCatagory4}
& - & - & - & - & - & - & - & 1
\\\addlinespace
\hline
\end{tabularx}
\newpage
\sectionheader{Data}
\begin{tabularx}{\textwidth}{l*{3}X}
\textbf{Catagory1}
& {7/3/16} & {7/4/16} & {7/5/16}\\
\addlinespace
{SubCatagory1}
& - & - & -
\\\addlinespace{SubCatagory2}
& - & - & -
\\\addlinespace
\hline
\textbf{Catagory2}
& {7/3/16} & {7/4/16} & {7/5/16}\\
\addlinespace
{SubCatagory1}
& - & - & -
\\\addlinespace
\hline
\textbf{Catagory3}
& {7/3/16} & {7/4/16} & {7/5/16}\\
\addlinespace
{SubCatagory1}
& - & - & -
\\\addlinespace{SubCatagory2}
& - & - & -
\\\addlinespace
\hline
\textbf{Catagory4}
& {7/3/16} & {7/4/16} & {7/5/16}\\
\addlinespace
{SubCatagory1}
& - & - & -
\\\addlinespace{SubCatagory2}
& - & - & -
\\\addlinespace{SubCatagory3}
& - & - & -
\\\addlinespace{SubCatagory4}
& - & - & -
\\\addlinespace
\hline
\textbf{Catagory5}
& {7/3/16} & {7/4/16} & {7/5/16}\\
\addlinespace
{SubCatagory1}
& - & - & 1
\\\addlinespace{SubCatagory2}
& - & 1 & -
\\\addlinespace{SubCatagory3}
& 1 & - & -
\\\addlinespace{SubCatagory4}
& - & - & -
\\\addlinespace
\hline
\end{tabularx}
\newpage
\bigskip
\newpage
\end{document}
答案1
我认为没有必要将表格拆分成两部分。删除一些冗余信息并将所有日期字符串合并到单个标题行中,将所有日期列列在一类似表格的环境。
%!TEX TS-Program = xelatex
%!TEX encoding = UTF-8 Unicode
\documentclass{article}
\usepackage{booktabs,fancyhdr,tabularx}
\usepackage[margin=2.5cm]{geometry}
\setlength\parindent{0pt}
\newcommand{\sectionheader}[1]{%
\textbf{#1}\par
\rule{\textwidth}{6pt}}
\newcommand\zcolumn[1]{%
{\begin{tabular}{c}#1\end{tabular}\linebreak[0]}}
\setlength{\heavyrulewidth}{0.12em}
\pagenumbering{arabic}
\pagestyle{fancy}
\lhead{Report Name: SomeOne}
\rhead{\thepage}
\cfoot{}
\begin{document}
\sectionheader{Data}
\begin{tabular*}{\textwidth}{@{} l @{\extracolsep{\fill}} *{11}c @{}}
\addlinespace
& \multicolumn{11}{c@{}}{Dates in late June and early July 2016}\\
\cmidrule{2-12}
& 6/25 & 6/26 & 6/27 & 6/28 & 6/29 & 6/30 & 7/1 & 7/2 & 7/3 & 7/4 & 7/5\\
\midrule
\textbf{Category1}\\
SubCategory1
& - & - & - & - & - & - & - & - & - & - & - \\
SubCategory2
& - & - & - & - & - & - & - & - & - & - & - \\
\addlinespace
\textbf{Category2}\\
SubCategory1
& - & - & - & - & - & - & - & - & - & - & - \\
\addlinespace
\textbf{Category3}\\
SubCategory1
& - & - & - & - & - & - & - & - & - & - & - \\
SubCategory2
& - & - & - & - & - & - & - & - & - & - & - \\
\addlinespace
\textbf{Category4}\\
SubCategory1
& - & - & - & - & - & - & - & - & - & - & - \\
SubCategory2
& - & - & - & - & - & - & - & - & - & - & - \\
SubCategory3
& - & - & - & - & - & - & - & - & - & - & - \\
SubCategory4
& - & - & - & - & - & - & - & - & - & - & - \\
\addlinespace
\textbf{Category5}\\
SubCategory1
& - & - & - & - & 1 & - & - & - & - & - & 1 \\
SubCategory2
& - & - & - & - & - & 1 & - & - & - & 1 & - \\
SubCategory3
& - & - & - & - & - & - & 1 & - & 1 & - & - \\
SubCategory4
& - & - & - & - & - & - & - & 1 & - & - & - \\
\bottomrule
\end{tabular*}
\end{document}
答案2
最后,我手动修复了这个问题,方法是在第二页的每一行中添加额外的“&”。我本来希望找到一些 latex 包来处理这个问题,但我找不到。