1

For external reasons, I need to make an actually tabular local TOC for a single section, and be able to annotate those sections with summaries. I did it, but I'm not happy with the way I abused subsubsection to achieve it.

Latex custom TOC of custom command is close, but I'm not sure how to adapt something like the \registerline command defined there to etoc, especially because etoc uses a single .toc file.

Here's an MWE:

picture of a rendered TeX file using the MWE below, starting with a regular TOC, followed by a section, then a tabular TOC with repeated summary lines

\documentclass[11pt]{article}
\usepackage{etoc}
\usepackage{lipsum}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{hyperref}

\author{Some Author}
\title{Some Title}

\begin{document}
\maketitle

\setcounter{tocdepth}{1}
\tableofcontents

\section{Super long section}

%% Where I'm trying to make a tabular table of contents
\begingroup % Localize changes here
\etocsetnexttocdepth{3}
\etocglobaldefs % necessary for \etocname etc... to survive &
\etocsettocstyle{
  \textbf{Things Included Here:}
  \begin{longtable}{p{6.5cm}p{0.75cm}p{3.5cm}} \toprule
  Document & Page & Summary \\ \midrule \endhead
}{\end{longtable}}
\etocsetstyle{subsection}
             {}
             {}
             {\etocname & \etocthelinkedpage}
             {}

\etocsetstyle{subsubsection}
             {}
             {}
             {& \hypersetup{hidelinks} {\etocname} \\}
             {}

\localtableofcontents
\endgroup

\subsection{First thing}

\etoctoccontentsline{subsubsection}{Summary of first thing}

\lipsum[1-2]

\subsection{Second thing}%{Summary of second thing}

\etoctoccontentsline{subsubsection}{Summary of second thing}

\lipsum[3]

\subsection{Third thing}%{Summary of third thing}

\etoctoccontentsline{subsubsection}{Summary of third thing}

\lipsum[3]

\end{document}
2
  • 1
    Welcome! Nice first question. What exactly are you unsatisfied with? I gather the output is what you want, so I assume it's the approach. I'd probably want something less in-the-document so I didn't have formatting as mixed up with content and I could do the same thing in another section without duplicating code. But that's me; I have no idea if that's you ;).
    – cfr
    Commented Sep 7, 2023 at 3:33
  • You could lose the longtable and add \parbox to the summary (and possibly the title). Commented Sep 7, 2023 at 14:29

1 Answer 1

0

I think your code is quite appropriate and only issue is that you can not use subsubsections in this section.

To fix this you can use a custom "sectionsummary" level. Then subsubsections can be used and shown in other tables of contents, but will not appear in this local TOC (whose tabular design anyhow does have no room for them).

Numerical level 6 is not shown by etoc, which explains some of the code below.

\documentclass[11pt]{article}
\usepackage{etoc}
\etocsetlevel{sectionsummary}{6}
\usepackage{lipsum}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{hyperref}

\author{Some Author}
\title{Some Title}

\begin{document}
\maketitle

\setcounter{tocdepth}{1}
\tableofcontents

\section{Super long section}

%% Where I'm trying to make a tabular table of contents
\begingroup % Localize changes here
%%%% \etocsetnexttocdepth{3} % moved later for better readability
\etocglobaldefs % necessary for \etocname etc... to survive &
\etocsettocstyle{
  \textbf{Things Included Here:}
  \begin{longtable}{p{6.5cm}p{0.75cm}p{3.5cm}} \toprule
  Document & Page & Summary \\ \midrule \endhead
}{\end{longtable}}
\etocsetstyle{subsection}
             {}
             {}
             {\etocname & \etocthelinkedpage}
             {}
\etocsetlevel{sectionsummary}{3}% unfortunately only numerical value accepted
                                % here, we would have hoped to use subsubsection
\etocsetlevel{subsubsection}{6}% make them invisible in this local TOC
\etocsetstyle{sectionsummary}
             {}
             {}
             {& \hypersetup{hidelinks}{\etocname} \\}% edited to remove stray space token
             {}

\etocsetnexttocdepth{sectionsummary}% here a level name accepted
\localtableofcontents
\endgroup

\subsection{First thing}

\etoctoccontentsline{sectionsummary}{Summary of first thing}

\lipsum[1-2]

\subsection{Second thing}%{Summary of second thing}

\etoctoccontentsline{sectionsummary}{Summary of second thing}

\lipsum[3]

\subsection{Third thing}%{Summary of third thing}

\etoctoccontentsline{sectionsummary}{Summary of third thing}

\lipsum[3]

\end{document}

edit: I should have used "subsectionsummary" rather than "sectionsummary" to better match the actual context. But this is cosmetic detail of code.

edit2: I removed a stray space token from the "sectionsummary" style, see now output:

TOC

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .