我在 中遇到了间距问题longtable
,其中使用 会multicolumn
拉长最后一列。示例如下。
建议的解决方案这个问题对我来说似乎不起作用(\fill
出现错误),但我怀疑问题是类似的。
\documentclass{article}
\usepackage{array}
\usepackage{booktabs}
\usepackage{longtable}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}b{#1}}
\begin{document}
\begin{center}
\begin{longtable}{@{\extracolsep{6pt}}*{5}{L{1.75cm}}}
\toprule\multicolumn{3}{l}{\textbf{Survey Code}} & \multicolumn{2}{r}{\textbf{Month/Year (Sample Size)}} \\ \midrule
\endfirsthead
\multicolumn{5}{c}%
{{\bfseries \tablename\ \thetable{} -- continued from previous page}} \\
\toprule\multicolumn{1}{l}{\textbf{Survey Code}} & \multicolumn{4}{r}{\textbf{Month/Year (Sample Size)}} \\ \midrule
\endhead
\midrule\multicolumn{5}{l}{{Continued on next page}} \\\bottomrule
\endfoot
\bottomrule
\endlastfoot
\multicolumn{3}{l}{Polling Organization} & \multicolumn{2}{r}{(Mo./Yr.) ($N=XXXX$)} \\[1em]
\multicolumn{5}{p{\textwidth}}{\footnotesize \emph{Survey question text goes here.}} \\[1em]
\\[.25em]
\multicolumn{1}{L{2cm}}{Response 1} & \multicolumn{1}{L{2cm}}{Response 2} & \multicolumn{1}{L{2cm}}{Response 3} & \multicolumn{1}{L{2cm}}{Response 4} & \multicolumn{1}{L{2cm}}{Response 5}\\\cmidrule{1-1}\cmidrule{2-2}\cmidrule{3-3}\cmidrule{4-4}\cmidrule{5-5}
\nopagebreak
\multicolumn{1}{p{2cm}}{20\%} & \multicolumn{1}{p{2cm}}{56\%} & \multicolumn{1}{p{2cm}}{6\%} & \multicolumn{1}{p{2cm}}{8\%} & \multicolumn{1}{p{2cm}}{10\%} \\[2em]
\end{longtable}
\end{center}
\end{document}
答案1
如果我正确理解了你的问题,那么你会喜欢下表(不幸的是,它不清楚,没有显示的行是什么,或者只有数字?):
(红线表示文本边框)
- 表格的列宽相等,由以下公式确定
p{\dimexpr0.2\textwidth-2\tabcolsep}
- 对于
\multicolumn
s 的定义是使用xparse
包
\documentclass{article}
\usepackage{booktabs, longtable, makecell}
\usepackage{xparse}
\NewExpandableDocumentCommand\mcl{O{1}m}
{\multicolumn{#1}{l}{#2}}
\NewExpandableDocumentCommand\mcr{O{1}m}
{\multicolumn{#1}{r}{#2}}
\newcommand\mcp[1]{\multicolumn{1}{p{0.16\linewidth}}{#1}}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}
\begin{document}
\begingroup
\begin{longtable}{ *{5}{p{\dimexpr0.2\textwidth-2\tabcolsep}}
}
\caption{Caption on the first page of the table}
\label{tab:longtable} \\
\toprule
\mcl[2]{\textbf{Survey Code}}
& \mcr[3]{\textbf{Month/Year (Sample Size)}} \\
\midrule
\endfirsthead
\caption[]{Caption on the first page of the table} \\
\toprule
\mcl[2]{\textbf{Survey Code}}
& \mcr[3]{\textbf{Month/Year (Sample Size)}} \\
\midrule
\endhead
\midrule[\heavyrulewidth]
\mcr[5]{r}{\small\textit{Continued on next page}} \\
\endfoot
\bottomrule
\endlastfoot
%%%% table body
\mcl[2]{Polling Organization}
& \mcr[3]{(Mo./Yr.) ($N=XXXX$)} \\
\midrule
\addlinespace
\multicolumn{5}{>{\small}p{\dimexpr\linewidth-2\tabcolsep}}{\emph{Survey question text goes here.}
\medskip
\lipsum[11]} \\ % dummy text
\addlinespace
{Response 1}
& {Response 2}
& {Response 3}
& {Response 4}
& {Response 5} \\
\cmidrule(r){1-1}\cmidrule(r){2-2}
\cmidrule(r){3-3}\cmidrule(r){4-4}\cmidrule{5-5}
20\,\% & 56\,\% & 6\,\% & 8\,\% & 10\,\% \\
\end{longtable}
\endgroup
\end{document}
\end{longtable}
\endgroup
\end{document}