如何使用 LaTex 多行重复下一页长表单元格内容并进行少许修改

如何使用 LaTex 多行重复下一页长表单元格内容并进行少许修改

鉴于此方法: 如何使用 \multirow 在 \longtable 的下一页上重复单元格内容

如果我想稍微“修改”重复的文本,以便在原始页面上用小脚本在其下方添加“下页继续”之类的内容,然后在接下来的页面上,用小脚本在其下方添加“上一页继续”...我该怎么做呢?

提前致谢!

编辑后添加:抱歉,但我似乎在这里遗漏了一些关键细节。基本上,我涉及两个文件 - 有一个 TeX 样式表文件,其中包含以下宏:

\def\mytablebegin{
\begin{longtable}[c]{|>{\centering\bfseries\tablefontsize}p{0.15\fourtabwid}|>{\centering\bfseries\tablefontsize}p{0.15\fourtabwid}|>{\tablefontsize}p{0.35\fourtabwid}|>{\tablefontsize\arraybackslash}p{0.35\fourtabwid}|}
\hline
\multicolumn{4}{|>{\color{white}\columncolor{color2}}c|}{}\\[-2ex]
\multicolumn{4}{|>{\color{white}\columncolor{color2}}c|}{\textbf{\large TABLE HEADER}}\\\hline
%\rowcolor{color3} 
\textbf{COLUMN1} & 
\textbf{COLUMN2} & 
\normfig \hfill\parbox[c]{0.35\fourtabwid - 4em}{\textbf{COLUMN3}} & 
\caufig \hfill\parbox[c]{0.35\fourtabwid - 4em}{\textbf{COLUMN4}}\\\hline
\endhead
\hline
\endfoot
\endlastfoot
}
\def\mytableend{
\end{longtable}
}

\usepackage{zref-abspage}
% Counter `topic@label' for automatic generation of label names
\makeatletter
\newcounter{topic@label}
\renewcommand*{\thetopic@label}{topic@\the\value{topic@label}}

% \topic@previous: Macro for remembering the previous topic
\global\let\topic@previous\relax
\global\let\lasttopic\relax
\newcommand*{\topic}[1]{%
  \begingroup
    \def\topic@put{\topicformat{#1}}%
    % Remember label name of previous topic
    \edef\topic@previouslabel{\thetopic@label}%
    % Set label to remember the page position
    \stepcounter{topic@label}%
    \zref@labelbyprops{\thetopic@label}{abspage}%
    % Compare topic with previous topic
    \def\topic@current{#1}%
    \ifx\topic@current\topic@previous
      % Check, whether is the previous topic with same name is
      % on the same page.
      \zifrefundefined{\topic@previouslabel}{%
        \topic@put
      }{%
        \zifrefundefined{\thetopic@label}{%
          \topic@put
        }{%
          \ifnum\zref@extractdefault{\topic@previouslabel}{abspage}{0}=%
                \zref@extractdefault{\thetopic@label}{abspage}\relax
          \else
            \topic@put
          \fi
        }%
      }%
    \else
      % New topic is always set
      \topic@put
    \fi
    % Remember this topic as previous topic for next topic
    \global\let\topic@previous\topic@current
  \endgroup
  \gdef\lasttopic{\topic{#1}}%
}
% Macro \topicformat formats the topic
\newcommand*{\topicformat}[1]{#1}
\makeatother

然后是实际的 TeX 模板文件,其中包含表格渲染代码,如下所示:

\newpage
\mytablebegin
\topic{\footnotesize TOPIC1} & \footnotesize SUBTOPIC1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize SUBLIST1 \nl SUBLIST2 \\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC2 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC3 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC4 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC5 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC6 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC7 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\hline
\topic{\footnotesize TOPIC2} & \footnotesize SUBTOPIC1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize \\\hline
\topic{\footnotesize TOPIC3} & \footnotesize SUBTOPIC1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize \\\hline
\topic{\footnotesize TOPIC4} & \footnotesize SUBTOPIC1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize \\\hline
\topic{\footnotesize TOPIC5} & \footnotesize SUBTOPIC1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize \\\hline
\topic{\footnotesize TOPIC6} & \footnotesize SUBTOPIC1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize SUBLIST1 \nl SUBLIST2 \\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC2 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC3 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\hline
\topic{\footnotesize TOPIC7} & \footnotesize SUBTOPIC1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize SUBLIST1 \nl SUBLIST2 \\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC2 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC3 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\hline
\lasttopic & \footnotesize SUBTOPIC4 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC5 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC6 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\cline{2-4}
\lasttopic & \footnotesize SUBTOPIC7 & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2\\\hline
\topic{\footnotesize TOPIC8} & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize \\\hline
\topic{\footnotesize TOPIC9} & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize \\\hline
\topic{\footnotesize TOPIC10} & \footnotesize SUBLIST1 & \footnotesize SUBLIST1 \nl SUBLIST2 & \footnotesize \\\hline
\mytableend

我在这里尝试做的是举个例子,假设 TOPIC1(因为它跨越 7 行)的内容太多,无法放在第一页,所以它从第二页重新开始。我想让它做的是在报告的第一页上,在实际文本“TOPIC1”下用 \tiny 字体放置一个小小的宣传语,上面写着“下页继续”,在第二页的“TOPIC1”下方用 \tiny 字体放置一个小小的宣传语,上面写着“接上一页”,以及在重复此单元格的每个后续页面上。

答案1

利用该包,longtable您可以轻松设置每页的标题和结尾,使用以下代码:

%First page heading
\hline
\bfseries Head 1 & \bfseries Head 2 & \bfseries Head 3\\[5ex]
\hline
\endfirsthead

%Following page headings
\multicolumn{3}{c}{\emph{Continued from previous page}} \\
\hline
\bfseries Head 1 & \bfseries Head 2 & \bfseries Head 3\\[5ex]
\hline
\endhead

%Following page endings
\hline
\multicolumn{3}{c}{\emph{Continued on next page}} \\
\endfoot

%Last page ending
\hline
\endlastfoot

我尝试在您提到的代码中输入这几行,并且成功了,现在您可以根据需要修改每个页面中的文本。完整代码如下:

\documentclass[11pt]{article}
\usepackage{lipsum} % for dummy text only
\usepackage{longtable}
\setlength{\arrayrulewidth}{1.2pt}

\usepackage[
  hmargin=2cm,
  vmargin=4cm,
  headsep=1pt,
  footskip=25pt,
]{geometry}

\usepackage{zref-abspage}[2010/03/26]

\makeatletter
% Counter `topic@label' for automatic generation of label names
\newcounter{topic@label}
\renewcommand*{\thetopic@label}{topic@\the\value{topic@label}}

% \topic@previous: Macro for remembering the previous topic
\global\let\topic@previous\relax
\global\let\lasttopic\relax
\newcommand*{\topic}[1]{%
  \begingroup
    \def\topic@put{\topicformat{#1}}%
    % Remember label name of previous topic
    \edef\topic@previouslabel{\thetopic@label}%
    % Set label to remember the page position
    \stepcounter{topic@label}%
    \zref@labelbyprops{\thetopic@label}{abspage}%
    % Compare topic with previous topic
    \def\topic@current{#1}%
    \ifx\topic@current\topic@previous
      % Check, whether is the previous topic with same name is
      % on the same page.
      \zifrefundefined{\topic@previouslabel}{%
        \topic@put
      }{%
        \zifrefundefined{\thetopic@label}{%
          \topic@put
        }{%
          \ifnum\zref@extractdefault{\topic@previouslabel}{abspage}{0}=%
                \zref@extractdefault{\thetopic@label}{abspage}\relax
          \else
            \topic@put
          \fi
        }%
      }%
    \else
      % New topic is always set
      \topic@put
    \fi
    % Remember this topic as previous topic for next topic
    \global\let\topic@previous\topic@current
  \endgroup
  \gdef\lasttopic{\topic{#1}}%
}
% Macro \topicformat formats the topic
\newcommand*{\topicformat}[1]{#1}
\makeatother

\begin{document}
\begin{longtable}{|p{3.2cm}|p{2.3cm}|p{10.5cm}|}

    %First heading
    \hline
    \bfseries Head 1 & \bfseries Head 2 & \bfseries Head 3\\[5ex]
    \hline
    \endfirsthead

    %Heading
    \multicolumn{3}{c}{\emph{Continued from previous page}} \\
    \hline
    \bfseries Head 1 & \bfseries Head 2 & \bfseries Head 3\\[5ex]
    \hline
    \endhead

    %Ending
    \hline
    \multicolumn{3}{c}{\emph{Continued on next page}} \\
    \endfoot

    % Last ending
    \hline
    \endlastfoot

  \topic{Topic 1}
    & Subtopic A  & There is some text here but could be small \\ \cline{2-3}
  \lasttopic
    & Subtopic B & \lipsum[1-3]  \\  \cline{2-3}
  \lasttopic
    & Subtopic C & \lipsum[1-2]   \\  \cline{2-3}
  \hline
  \topic{Topic 2}
    & Subtopic A  & \lipsum[1-3]   \\ \cline{2-3}
  \lasttopic
    & Subtopic B & \lipsum[1-2]  \\  \cline{2-3}
  \lasttopic
    &  Subtopic C & \lipsum[1-2]   \\  \cline{2-3}
\end{longtable}
\end{document}

另一个建议:如果您想避免使用所有这些行,您可以添加booktabs提供和命令的包\toprule\midrule创建\bottomrule“更好看的”(如果您喜欢它:-))表。

相关内容