0

Given this approach: How to Repeat Cell Content on Next Page for \longtable using \multirow

What if I wanted to slightly "modify" the text that is repeating so that on the originating page I want to add something like "Continued on next page" below it in tiny script, then on the following subsequent pages, add "Continued from previous page" below it in tiny script.. How would I do that?

Thanks in advance!

Edited to add: I apologize, but it looks like I left out some key details here. Basically, I have two files involved - there's a TeX style sheet file, which contains the macro as follows:

\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

And then the actual TeX template file, which contains the table rendering code as follows:

\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

What I'm trying to do here as an example, say TOPIC1 (as it spans across 7 rows) has too much content to fit on the first page, so it starts up again on page 2. What I am trying to make it do is put a little tiny blurb under the actual text "TOPIC1" in \tiny font that reads "Continued on next page" on the first page of the report, and \tiny font that reads "Continued from previous page" below "TOPIC1" on the second page, and every subsequent page that this cell is repeated on.

0

With the package longtable you can easily set the heading and ending of each page, using this code:

%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

I tried to enter this lines in the code you mentioned and it worked, now you can modify the text in each page as you want. The entire code is:

\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}

Another tip: if you want to avoid using all these lines you could add the booktabs package, that provides the \toprule, \midrule and \bottomrule commands, to create a "better looking" (if you like it :-)) table.

| improve this answer | |
  • Thank you for your help - I added a bit more of an explanation of what I am trying to make it do, as I want to actually put that text in the repeating column instead of across the top. – Amy Jun 18 '15 at 19:22
  • @Amy I'm not sure how this could be achieved (unfortunately I'm not an expert :-) ); however, I could not run your code, would you mind add a MWE that is compilable (with \documentclass{..} and so on)? – MarcoG Jun 18 '15 at 20:24
  • I just heard back from the client - he is happy with your solution, so thank you so much! I am all good now. – Amy Jun 19 '15 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.