我是 StackExchange 的新手,因此欢迎提出任何改进我的问题框架的建议。
我在对齐表格标题时遇到了一些麻烦。由于我需要横向、多页表格,因此我结合使用 threeparttablex 和 longtable。我发现注释掉下面 MWE 中第 10 行的边距调整可以解决我的问题,但我确实希望在文档的其余部分保持边距不变。
注意:我的文档中其他“常规”三部分表(无 x、无 longtable)的标题都很好。此外,我尝试在该表的多个位置使用 \centering,但没有帮助。
我的问题是:如何将表格标题与此表格对齐,同时保持边距为 2.6 厘米?提前致谢!
\documentclass{book}
\usepackage[flushleft]{threeparttable}
\usepackage{longtable}
\usepackage{pdflscape}
\usepackage{threeparttablex}
\usepackage{caption}
\usepackage{booktabs}
\usepackage[margin=2.6cm]{geometry} %commenting this out fixes the caption alignment
%adjust table caption setup
\DeclareCaptionLabelSeparator*{spaced}{\\[2ex]}
\captionsetup[table]{textfont=it,justification=raggedright,singlelinecheck=false,labelsep=spaced, skip=0pt}
\begin{document}
\begin{landscape}
\begin{ThreePartTable}
\begin{TableNotes}
\small
\item \textit{Note.} Table notes
\end{TableNotes}
\begin{longtable}{p{1cm}p{1cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}}
\caption{My caption}\\
\toprule
Header & Header & Header & Header & Header & Header & Header \\
\midrule
\endfirsthead
\multicolumn{7}{l}{\textit{My caption (continued)}}\\ %cheating a little bit here
\toprule
Header & Header & Header & Header & Header & Header & Header \\
\midrule
\endhead
\midrule
\multicolumn{7}{r}{{\textit{Continued on next page}}} \\
\midrule
\endfoot
\bottomrule
\insertTableNotes
\endlastfoot
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
1 & 1 & 1 & 1 & 1 & 1 & 1\\
\end{longtable}
\end{ThreePartTable}
\end{landscape}
\end{document}
答案1
对此可能有更好的自动解决方案,但作为快速修复,您可以手动调整标题的边距:
\captionsetup{margin=1.4cm}
您可以在文档的开头进行设置,但由于表格的宽度可能都不同,因此您可能需要针对每个表格分别进行调整:将上述行放在每个表格的开头,如下所示:
%[...]
\begin{longtable}{p{1cm}p{1cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}}
\captionsetup{margin=1.4cm} % <--- adjust as needed
\caption{My caption}\\
%[...]
答案2
您需要定义标题的宽度:
\setlength\LTcapwidth{\dimexpr17cm+14\tabcolsep}
其中17cm
是列宽的总和以及周围长度14\tabcolsep
的总和。完整代码是:tabcolsep
%%%% 3parttablex %%%%%
%---------------------------------------------------------------%
% my answer ... 2017-10-14 %
% https://tex.stackexchange.com/questions/395852/ %
% a-long-table-in-the-landscape-page/396077#396077 &
%---------------------------------------------------------------%
% special: table notes are inserted in %
% \endfoot and \endlastfoot %
%---------------------------------------------------------------%
\documentclass[a4paper, 11pt, oneside]{book}
\usepackage[margin=30mm]{geometry}
\usepackage{ragged2e}
\usepackage{array,
booktabs,
longtable,
makecell}
\usepackage[referable]{threeparttablex}
\usepackage{caption}
\DeclareCaptionLabelSeparator*{spaced}{\\[1ex]}
\captionsetup[table]{textfont=it,
justification=raggedright,
singlelinecheck=false,
labelsep=spaced,
skip=1ex}
\usepackage{siunitx}
\usepackage{pdflscape}
\usepackage{lipsum} % for dummy text in captions
\begin{document}
\begin{landscape}
\sffamily
\setlength\tabcolsep{4pt}
\centering
\begin{ThreePartTable}[
\setlength\LTcapwidth{\dimexpr17cm+14\tabcolsep}
%
\begin{TableNotes}[para,flushleft]\footnotesize
\note{General table notes}
\item[*] first note
\item[**] second note
\end{TableNotes}
%
\begin{longtable}{p{1cm}p{1cm}p{3cm}p{3cm}p{3cm}p{3cm}p{3cm}}
\caption{My caption. \lipsum[66]}\\
\toprule
Header & Header & Header & Header & Header & Header & Header \\
\midrule
\endfirsthead
\caption*{My caption. \lipsum[66]}\\
\toprule
Header & Header & Header & Header & Header & Header & Header \\
\midrule
\endhead
\midrule
\multicolumn{7}{r}{{\textit{Continued on next page}}} \\
\endfoot
\midrule[\heavyrulewidth]
\insertTableNotes
\endlastfoot
1 & 1 &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