To make the structure of documents (here: my PhD-thesis) comprehensible straight from the ToC, I would like to insert some key words or key phrases in each element of the ToC. I saw this device in a teaching book and I thought it would be a helpful little improvement for longer documents.

My first description of the desired layout lacked of precision, I hope this one is more clear.

Requirements for user-friendlybility: I am looking for a solution that handles key words or key phrases which belong to one part, section etc. in the following way:

a) puts key words/phrases in rows

b) divides them through hyphens

c) one line under the actual part, section etc.

d) key words/phrases without page number

e) depending on the number of key words/phrases it can exceed one line

It should look like this:


1 section .............................1

key word 1 - key phrase 2 - key word 3

1.1 subsection ...............................5

key word 1 - key phrase 2 - key word 3 -

key word 4 - key phrase 5 - key word 6

Requirement for writer-friendlybility: To make it easier for the writer of the document one command is hoped-for that adapts to a given section, part etc. without any specification within the command in order to prevent him from adjusting the command every time when he is copying it from one sections to a part, subsection, etc.

In the .tex-file it should look like this:

bla bla \command{keyword1} few lines or pages of bla bla \command{keyword2} ....

bla bla \command{keyword1} few lines or pages of bla bla \command{key phrase2} ....

Does anyone have an idea how to do it?

PS: To convert the keywords in the toc into hyperref-keywords take a look here: Hyperref-ize the keywords in toc. It works with egregs solution.

  • Welcome to tex.sx! Usually, we don't put a greeting or a "thank you" in our posts. While it might seem strange at first, it is not a sign of a lack of politeness, but rather part of our trying to keep everything very concise. Upvoting the preferred way here to say "thank you" to users who helped you.
    – doncherry
    Jun 3, 2011 at 20:59
  • you can use the command \addtocontens Jun 3, 2011 at 20:59
  • 1
    @Marco: it would be great if you write this as answer, perhaps elaborate a bit.
    – Stefan Kottwitz
    Jun 3, 2011 at 21:25
  • I've updated my answer, adding a new example that satisfies all but the last requirement (the sectional unit must be explicitly declared, but this is easily done using a number). Jun 4, 2011 at 14:19

3 Answers 3




\newrobustcmd{\kwsep}{~-- }




Abc \keyword{key1} def \keyword{key2}


Ciao \keyword{key3} ciao \keyword{key4}




I'll leave to the OP the task of redefining \formatkwsection and \formatkwsubsection to suit his needs.


The tocloft package provides this kind of functionality for chapters: \cftchapterprecistoc; it's not hard to create a similar command for sections. Here's a small example:


% Define a \cftsectionprecistoc
% based on the existing \cftchapterprecistoc
  {\leftskip \cftsecindent\relax
   \advance\leftskip \cftsecnumwidth\relax
   \rightskip \@tocrmarg\relax

\chapter{A chapter title}
\cftchapterprecistoc{some keywords}

\section{A section title}
\cftsectionprecistoc{some more keywords}
\subsection{A subsection title}

partial output of code

  • & Gonzalo: Both ways dont result in the layout I am looking for. I would prefer to have the key words or key phrases which a) belong to one part, section etc. in rows b) divided through hyphens c) one line under the actual part, section etc. (as both of you created) d) key words/phrases without page number. Like: "key word/phrase - key word/phrase - etc.." In addition, I would like to have ONE command that adapts to a given section, part etc. without any specification within the command, because I am copying from sections to parts, subsections, etc. and dont want to adjust all the time.
    – Philip
    Jun 4, 2011 at 0:22
  • 2
    @Philip, I'm not sure that you should treat this site as a personal coding resource. Most solutions on the site are proof of concept, and designed to get you started by showing you how you can do things. I think both of our solutions do this quite adequately, especially since you mentioned none of these other requirements in your question. As for the requirements, nothing prevents you formatting the content of the keyword line with hyphens, either with your own markup or manually. We both gave solutions for (c) and (d). Your last requirement isn't very easy, I don't think.
    – Alan Munn
    Jun 4, 2011 at 1:56
  • thank you for your answer and the time for creating the code. I am knew in the forum world and I realy dont know much about the code of these code worlds (maybe a topic for forum question). So I dont know what can be ask and what cannot be ask. But I have the strong feeling that when there is a question that improves the readability of documents (what seems like one of the main purposes of latex) it should be ask - even when it looks like exploiting this site "as a personal coding resource". I admit: my first question was not precise. I hope I changed it to a better way.
    – Philip
    Jun 4, 2011 at 9:39

You can use the \addtocontents and/or the \addcontentsline commands; you can control many aspects of the text to be added:




\chapter{Test chapter}
\addtocontents{toc}{Here we add some text without page number.\par}

\section{Test section}


\addcontentsline{toc}{subsection}{Some text formatted like an unnumbered subsection}


\subsection{Test subsection}

\addcontentsline{toc}{chapter}{Some text formatted like a chapter and with page number\protect\numberline{}}


\section{Another test section}



EDIT: taking into account the new requirements, I defined a new command \AddToToC with two mandatory arguments: the first one indicates the level of the sectional unit (-1 for parts, 0 for chapters, 1 for sections, etc...) and the second one contains the text that will be added to the ToC (the keywords); here's the definition of the command and and example of its use:



% \AddToToC{<level>}{<text>}


\part{Test part}
\AddToToC{-1}{some keywords for the part.}

\chapter{Test chapter one}
\AddToToC{0}{some keywords for the chapter.}

\section{Test section}
\AddToToC{1}{some keywords for the section.}

\subsection{Test subsection}
\AddToToC{2}{some keywords for the subsection.}



The lengths used are those of the book document class; other document classes will require adjusting the lengths. The command doesn't satisfy the last requirement, but all it's required is a simple change to the first argument.

  • @Medina: I dont want to bother you, but it is still not the desired result. I hoped that there is a command with an additional feature. Example: \begin{document} \section{Test Part} bla bla \command{keyword1} few pages of bla bla \command{keyword2} .... \end{document} The desired layout in the toc (as in my tried-hard-to-specify-but-failed-version on the top): 1.1 Test Part keyword 1 - keyword 2 - ... I hope you forgive my constant complaints.
    – Philip
    Jun 4, 2011 at 22:08

You must log in to answer this question.

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