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
.
\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}|}
\hline
\endfoot
\hline
\bfseries Head 1 & \bfseries Head 2 & \bfseries Head 3\\[5ex]
\hline
\endhead
\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}
\hline
\end{longtable}
\end{document}

Remarks:
- 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.