1

In short, I need to recode the table of contents, as I intend to include a short intro or summary as to what the chapter is about and all. Of course, if a package is already constructed for this purpose, that would be great too.

\begin{enumerate}
  \item \Nameref{<chapter-number>} \hfill \Pageref{<chapter-number>}
        This chapter is about blah.
\end{enumerate}

However, I don't want to constantly keep labeling every chapter of the book to go back and update this over and over.

Is there any code for \Nameref and \Pageref commands above (which function similar to \nameref and \pageref but reference the chapter number directly)?

  • 2
    I think you want something like tex.stackexchange.com/a/10189/1952 – Ignasi Jun 1 '17 at 13:55
  • 1
    Depends on the class you use (you give no information), I'd simply add the intro directly into the toc from right after the appropriate \chapter cmd in your doc. For example, the memoir class has build in features to do this. If you're using another class, the memoir code can easily be copied. – daleif Jun 1 '17 at 14:38
  • @daleif I was using a book class, but I think something like that could be changed. First time I heard of memoir. – Mad Maniac Jun 1 '17 at 18:07
  • Look up \chaptertocprecis in the manual. It something presis. Memoir should be a drop in replacement for book, already contains the code from a lot of packages – daleif Jun 1 '17 at 18:14
2

A version with automatic label generation and a helpchapter associated counter. The \label is injected after \refstepcounter{chapter} and is prefixed with helpchapter:

The macro \DisplayEnumTocLine{Foo} uses enumi as counter and retracts the name and page reference as \nameref{helpchapter:\number\value{enumi}} etc. The content of the mandatory argument is displayed as description text.

The starred version of \DisplayEnumTocLine does not generate hyperlinks for the name and page references, the example shows usages of both versions.

(Note: The xassoccnt package is not really necessary here, but it simplifies the automatic stepping of helpchapter here).

\documentclass{book}

\usepackage{enumitem}
\usepackage{xassoccnt}

\newcounter{helpchapter}
\DeclareAssociatedCounters{chapter}{helpchapter}

\usepackage{xpatch}

\makeatletter
\xpatchcmd{\@chapter}{%
  \refstepcounter{chapter}%
}{%
  \refstepcounter{chapter}%
  \label{helpchapter:\number\value{helpchapter}}%
}{}{}

\NewDocumentCommand{\DisplayEnumTocLine}{sO{helpchapter:}+m}{%
  \IfBooleanTF{#1}{%
    \nameref*{#2\number\value{enumi}} \hfill  \pageref*{#2\number\value{enumi}}% 
  }{%
    \nameref{#2\number\value{enumi}} \hfill  \pageref{#2\number\value{enumi}}% 
  }%

  #3%
}


\makeatother

\usepackage{hyperref}

\usepackage{blindtext}



\begin{document}

\begin{enumerate}
\item \DisplayEnumTocLine{A foo chapter}
\item \DisplayEnumTocLine*{\blindtext} 
\end{enumerate}

\chapter{Foo chapter}

\chapter{Other chapter}



\end{document}

enter image description here

1

You can add your additional information to the ToC:

\documentclass{book}

\newcommand*{\addchapterinfo}[1]{%
  \addcontentsline{toc}{chapterinfo}{#1}%
}
\makeatletter
\newcommand{\l@chapterinfo}[2]{%
  \begingroup
    \leftskip 1.5em% same as \l@chapter uses
    \noindent #1\par
  \endgroup
  \addvspace{.5\baselineskip}% add additional vertical space  
}
\makeatother

\usepackage{mwe}

\begin{document}
\tableofcontents
\chapter{First Chapter}
\addchapterinfo{This is additional text for the chapter entry}
\lipsum

\chapter{Second Chapter}
\addchapterinfo{\blindtext}
\lipsum[1]
\section{First Section in Second Chapter}
\lipsum

\end{document}

ToC with additional chapter info and section

If you don't like the section entries in the ToC, use \setcounter{tocdepth}{0}. This will result in:

ToC with additional chapter info but without sections

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.