I've created a LaTEX document that has several large tables that span multiple pages using long table. The table has several Topics (column 1) and Topics (column 2). The issue is that on the second page I have an empty column 1, but the subtopics are listed nicely in column 2. Can you tell me how to get "Topic 1" on to page 2 as well?

Here's some example code :

\usepackage{lipsum} % for dummy text only
\usepackage{longtable}%Setup to allow tables to span multiple pages and repeat headers on 
                      %next page 
\setlength{\arrayrulewidth}{1.2pt}% Set all table lines thicker than their 0.4pt default

%--------------------Setup Margins ---------------------
\textheight 9in
\setlength{\footskip}{25pt} % 25pts

    \begin{longtable}{|p{3.2cm}|p{2.3cm}|p{10.5cm}|} \hline 
         \endfoot % force a footer here 
        \bf{Head 1} & \bf{Head 2} & \bf{Head 3}\\[5ex]   \hline \endhead

 \multirow{3}{*}{Topic 1}
&Subtopic A  & There is some text here but could be small   \\ \cline{2-3}
 & Subtopic B & \lipsum[1-3]  \\  \cline{2-3}
 &  Subtopic C & \lipsum[1-2]   \\  \cline{2-3}
 \multirow{3}{*}{Topic 2}
 &Subtopic A  & \lipsum[1-3]   \\ \cline{2-3}
 & Subtopic B & \lipsum[1-2]  \\  \cline{2-3}
 &  Subtopic C & \lipsum[1-2]   \\  \cline{2-3}

2 Answers 2


The following example implements the logic: Each subtopic has a topic. If a subtopic of a topic follows a subtopic of the same topic on the same page, then the topic is suppressed. That means that the topic is repeated for the first subtopic on a new page, if necessary.

Each topic in the first column is set by \topic{...}. Repeated topics can be abbreviated by \lasttopic. The formatting of the topic can be changed by redefining \topicformat.

\usepackage{lipsum} % for dummy text only



% Counter `topic@label' for automatic generation of label names

% \topic@previous: Macro for remembering the previous topic
    % Remember label name of previous topic
    % Set label to remember the page position
    % Compare topic with previous topic
      % Check, whether is the previous topic with same name is
      % on the same page.
      % New topic is always set
    % Remember this topic as previous topic for next topic
% Macro \topicformat formats the topic

  \bfseries Head 1 & \bfseries Head 2 & \bfseries Head 3\\[5ex]
  \topic{Topic 1}
    & Subtopic A  & There is some text here but could be small \\ \cline{2-3}
    & Subtopic B & \lipsum[1-3]  \\  \cline{2-3}
    & Subtopic C & \lipsum[1-2]   \\  \cline{2-3}
  \topic{Topic 2}
    & Subtopic A  & \lipsum[1-3]   \\ \cline{2-3}
    & Subtopic B & \lipsum[1-2]  \\  \cline{2-3}
    &  Subtopic C & \lipsum[1-2]   \\  \cline{2-3}



  • Setting of \textheight is overwritten by the page layout setting via geometry.
  • \bf is outdated (LaTeX2.09), LaTeX (LaTeX2e) uses \bfseries or \textbf. Both \bf and \bfseries do not have an argument. The setting is active until the current group (table cell in this case) ends.
  • center is an environment, \centering is a command. In this case both are not needed, because the longtable is centered horizontally by default.
  • I have removed multirow, the positioning of the topic somewhere between the lines looked too odd, IMHO.
  • Thanks so much this is awesome, exactly what I was trying to achieve. I do notice I had to compile twice to get rid of Topic 1 on top of Topic 1 (i.e. it put it twice in page 1). So it must use the aux file to create the counter. Is there a way around this (different Chunk size for example) that would get it sorted on the first compile? The only reason I ask this is because this is run off an online server and it is a little bit slow to compile twice.... Thank you very much for this - it's a huge help! Dan
    – Dan
    Oct 26, 2012 at 17:09
  • @Dan Yes, references always need two runs. There is no way around, because, when the table row is typeset, it is not known, on which page the table row might be put. Oct 26, 2012 at 18:58
  • @HeikoOberdiek: Is there a way to avoid having to call \lasttopic after each row?
    – mdd
    Jul 26, 2016 at 15:37
  • This is wonderful, and it's the solution to a very similar problem that I've been trying to work through. I have an issue with multiple groupings like: Topic 1 & Sub-topic A & 1 \\ Topic 1 & Sub-topic A & 2 \\ Topic 1 & Sub-topic B & 3 \\ Topic 1 & Sub-topic B & 4 \\ Topic 2 & Sub-topic A & 5 \\ Topic 2 & Sub-topic A & 6 \\ Topic 2 & Sub-topic B & 7 \\ Topic 2 & Sub-topic B & 8 \\ ... Is there a way to expand your topic macro to manage multiple different levels of topics (a vector of them)? Oct 31, 2017 at 20:42

For people who may find this in the future, I needed the version I described in my comment from October 31, 2017 which generalizes to multiple columns of topics. It is now available here: https://github.com/paolobrasolin/topiclongtable

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.