作为背景请参阅我的回答这个问题。
我想知道,是否有可能tablenotes
在途中(自动)分割页面,每个页面上仅显示在此页面上使用的项目。例如,第一页tablenotes
仅包含从 1 到 7 的项目,而第二个包仅包含项目 1、8 和 12。
首先,如果可以定义两个tablenotes
并在第一个表页上使用第一个,在包含的第二个页面上使用第二个longtable
,我会很高兴。
答案1
这 是 很多 人 都 容易 解决 的 问题TableNotes
.
这里我重写了TableNotes
环境,并\insertTableNotes
增加了一个强制参数来命名表注释。注意,如果具有特定名称的表注释(已经)存在,则不会进行检查。
您可以根据需要设置任意数量的表格注释(参见示例的第二页)。但是,当然,只有两个音步longtable
,因此您只能设置两组不同的注释。(如果我能弄清楚如何在表格中间更改音步,那么就有可能实现注释的自动化。但到目前为止,还没有成功。)
结果:
代码:
\documentclass[11pt, oneside]{book}
\usepackage[a4paper,
hmargin={2.5cm},
top=2.5cm,
bottom=3.5cm]{geometry}
\usepackage{caption}
\usepackage[table]{xcolor}
\usepackage{array, ltablex, threeparttablex}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\setlength\extrarowheight{3pt}
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\makeatletter
% rewritten macros from threeparttablex
\renewenvironment{TableNotes}[2][]{%
\expandafter\gdef\csname TPTL@optarg@#2\endcsname{#1}%
\expandafter\def\csname TPTL@collector@#2\endcsname##1{%
\expandafter\long\expandafter\gdef\csname TPTL@body@#2\endcsname{##1}}%
\expandafter\gdef\csname TPTL@body@#2\endcsname{}%
\expandafter\Collect@Body\csname TPTL@collector@#2\endcsname}{}
% original code
%%%%\newenvironment{TableNotes}[1][]{
%%%% \gdef\TPTL@optarg{#1}%
%%%% \Collect@Body\TPTL@collector}{}
%%%%\newcommand\TPTL@collector[1]{%
%%%% \long\gdef\TPTL@body{#1}}
%%%%% the macro used to store the tablenotes contents
%%%%\gdef\TPTL@body{}
% rewritten macros from threeparttablex
% added argument
\renewcommand\insertTableNotes[1]{%
% first we need to know the width of the longtable, remember that it
% will only settle after a few compilations
\noalign{\begingroup
\setlength\TPTL@width{0pt}
\renewcommand\LT@entry[2]{\global\advance\TPTL@width by ##2}
\@nameuse{LT@\romannumeral\c@LT@tables}
\ifdim\TPTL@width<\TPTminimum\relax\global\TPTL@width=\TPTminimum\fi
\endgroup}
% then add the table notes inside a \parbox of the required width
\multicolumn{\LT@cols}{c}{%
\makebox[0pt][c]{%
\parbox{\TPTL@width}{%
\let\TPT@hsize\@empty% otherwise the width is not reset
% correctly as \TPT@hsize messes with
% \@parboxrestore
\let\TPToverlap\relax%
% added
\expandafter\let\expandafter\TPTL@optarg\csname TPTL@optarg@#1\endcsname
\begin{tablenotes}[\TPTL@optarg]%
\TPTL@font%
% changed
\csname TPTL@body@#1\endcsname
% original
%%%%\TPTL@body
\end{tablenotes}
}%
}%
}%
}
\makeatother
\begin{document}
\begin{ThreePartTable}
\begin{TableNotes}[flushleft]{1}\footnotesize
\item \textbf{Table Notes:}
\item[1] textetxt.
\item[2] textetxt.
\item[3] textetxttextetxttextetxttextetxttextetxttextetx ttextetxt textetxt textetxttextetxttex tetxttextetxttextetxttextetxt textetxttextetxt textetxt.
\item[4] textetxt.
\item[5] textetxt.
\item[6] textetxt.
\item[7] textetxt.
\item[8] textetxt.
\item[9] textetxt.
\item[10] textetxt.
\item[11] textetxt.
\item[12] textetxt.
\end{TableNotes}
\begin{TableNotes}[flushleft]{2}\footnotesize
\item \textbf{Table Notes:}
\item[1] textetxt.
\item[8] textetxt.
\item[12] textetxt.
\end{TableNotes}
\begin{TableNotes}[flushleft]{3}\footnotesize
\item \textbf{Additional Notes:}
\item foo
\item bar
\item baz
\end{TableNotes}
%
\begin{tabularx}{\textwidth}{| X || c | C | c | }
\caption{holder holder holder holder holder holder holder holder holder holder holder holder holder holder holder holder.}
\label{ProCons_CSM_DTM_SSM} \\
\hline
& \multicolumn{3}{c|}{\textbf{Hooooolder}} \\
\cline{2-4}
\textbf{holder} & holder & holder & holder \\
\hline\hline
\endfirsthead
\hline
& \multicolumn{3}{c|}{\textbf{Hooooolder}} \\
\cline{2-4}
\textbf{holder} & holder & holder & holder \\
\hline\hline
\endhead
\hline
\insertTableNotes{1}\medskip\\
\hline
\multicolumn{4}{r}{\textit{Continue on the next page}} \\
\endfoot
\hline
\insertTableNotes{2}\medskip\\
\hline
\insertTableNotes{3}\medskip\\
\hline
\endlastfoot
% table content
holder & holder & holder & \cellcolor{green!25} no \\
holder & holder & holder & \cellcolor{green!25} no \tnote{1} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\hline
\textbf{holder} & holder & holder & holder \\
\hline
holder & holder & holder & \cellcolor{green!25} no \tnote{2} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\hline
holder & holder & holder & \cellcolor{green!25} no \tnote{3} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder holder\\
\hline
\textbf{holder} & holder & holder & holder \\
\hline
holder & holder & holder & \cellcolor{green!25} no \tnote{4} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\hline
holder & holder & holder & \cellcolor{green!25} no \tnote{5} \\
\hline
holder holder holder holder holder & holder holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\hline
\textbf{holder} & holder & holder & holder \\
\hline
holder & holder & holder & \cellcolor{green!25} no \tnote{6} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder holder holder holder & \cellcolor{green!25} holder\\
\hline
holder & holder & holder & \cellcolor{green!25} no \tnote{7} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\hline
\textbf{holder} & holder & holder & holder \\
\hline
holder & holder & holder & \cellcolor{green!25} no \tnote{8} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\hline
holder & holder & holder & \cellcolor{green!25} no \tnote{1} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\hline
\textbf{holder} & holder & holder & holder \\
\hline \hline
holder & holder & holder & \cellcolor{green!25} no \tnote{12} \\
\hline
holder holder holder holder holder & holder & \cellcolor{green!25} holder & \cellcolor{green!25} holder\\
\end{tabularx}
\end{ThreePartTable}
\end{document}