7

I'm using titlecontens offered by titletoc package to format the entries in toc, lot and lof. For a multiline entry, the default location of its corresponding page number is after the last line of this entry. Is there any way to place this number after the first line of this entry?

5

Thanks for your solution! I just found another one and post here. The basic idea is to define entries of toc/lof/lot in a form of 1*3 table and heading, caption, and page are the three elements of this table. The following is the code to define such a table.

\titlecontents{figure}[0pt]
{\normalfont\mdseries\singlespace}
{\contentspush{\makebox[7em][l]{FIGURE \thecontentslabel:}}\begin{tabular}[t]{@{}p{11cm}@{}}}
{\hspace{-2em}\begin{tabular}[t]{p{11cm}}}
{\end{tabular}\hfill\contentspage} 
4

This can be avoided if you specify a shorter section title for the optional argument to \section[..]{...}, as in:

\documentclass{article}
\begin{document}
\tableofcontents
\section{A regular section title}
\section[A short ToC title]%
  {This is a section with an extremely long title %
   that spans at least two lines in the table of contents}
\section{A regular section title}
\end{document}

However, if this cannot be avoided, the titletoc package provides a means for manipulating each entry of the table of contents on a per-entry basis. This is possible using the \titlecontents command. You would first use this to set the default formatting of all sections. And then, just before the section that you want to format differently, you modify \titlecontents and switch back again afterwards. The following minimal working example illustrates this:

\documentclass{article}
\usepackage{titletoc}% http://ctan.org/pkg/titletoc
\begin{document}

% -------------- DEFAULT section formatting
\titlecontents{section}%
  [3.8em]% Left indent
  {\bfseries}% % above-code
  {\contentslabel{2.3em}}% Numbered format
  {\hspace*{-2.3em}}% Numberless format
  {\hfill\contentspage}% Filler page format
  []% Separator

\tableofcontents

\section{A regular section title}

% -------------- MODIFIED section formatting
\titlecontents{section}%
  [3.8em]% Left indent
  {\bfseries}% % above-code
  {\contentslabel{2.3em}}% Numbered format
  {\hspace*{-2.3em}}% Numberless format
  {\hfill\smash{\raisebox{\baselineskip}{\contentspage}}}% Filler page format
  []% Separator


\section{This is a section with an extremely long title %
  that spans at least two lines in the table of contents}

% -------------- REVERTED section formatting
\titlecontents{section}%
  [3.8em]% Left indent
  {\bfseries}% % above-code
  {\contentslabel{2.3em}}% Numbered format
  {\hspace*{-2.3em}}% Numberless format
  {\hfill\contentspage}% Filler page format
  []% Separator

\section{A regular section title}

\end{document}

The modified ToC section formatting raises \contentspage (the place holder for the page on which the section appears) by \baselineskip, pushing it up to be on the same level as the first line. If you had 3 lines in your section heading, push it up by 2\baselineskip, and so on. \smash ensures that the raised boxed does not affect the interline skip.

ToC formatting

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.