Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This might be a duplicate, but I am interested in customising the ToC appearance of chapter titles for \chapter commands placed:

  1. in the front and back matter, and
  2. after the \appendix command in the main matter.

I only wish to change font series (to medium) and shape (to italic) as shown below. (Vertical spacing between front matter chapter titles probably needs to be reduced as well.)

enter image description here


At the moment I'm using the standard document class book and:

\usepackage[nottoc]{tocbibind} % nottoc option for inclusion of LoT/LoF/Bib in ToC
\usepackage{hyperref}
share|improve this question
add comment

2 Answers

up vote 2 down vote accepted

The solution of Gonzalo Medina uses package titletoc that does not work well with hyperref, because it extracts the heading number of the entry in the table of contents (and LOF, LOT) and sets it outside the link.

The following solution patches \l@chapter, \l@section, …, which are responsible for the formatting of the entry in the table of contents to add \TocTitleFormat. Depending on the switch \ifTocMainMatter, \TocTitleFormat does nothing or adds \textit for the title. If \itshape is used instead, also the page number would be in italic.

Similar to Medina's solution \frontmatter and friends are patched to add the setting of the switch \ifTocMainMatter into the .toc file.

Since hyperref is used, likely also bookmarks are generated. The same style can be applied to them via package bookmark.

\documentclass{book}
\usepackage[nottoc]{tocbibind}
\usepackage{etoolbox}
\usepackage{hyperref}
\usepackage{bookmark}
\bookmarksetup{numbered,open}

\makeatletter
\newcommand*{\PatchTocEntry}[1]{%
  \expandafter\@PatchTocEntry\csname l@#1\expandafter\endcsname
  \csname org@l@#1\endcsname{org@l@#1}%
}
\newcommand*{\@PatchTocEntry}[3]{%
  \@ifdefinable{#3}{%
    \let#2#1%
    \renewcommand*{#1}[1]{%
      #2{\TocTitleFormat{##1}}%
    }%
  }%
}
\@for\@tmp:=chapter,section,subsection,subsubsection,paragraph,subparagraph\do{
  \PatchTocEntry{\@tmp}%
}
\newif\ifTocMainMatter
\let\ifTocMainMatter\if@mainmatter
\newcommand*{\SetTocMainMatter}[1]{%
  \addtocontents{toc}{%
    \expandafter\protect\csname TocMainMatter#1\endcsname
  }%
  \begingroup
  \edef\x{\endgroup
    \noexpand\bookmarksetup{%
      italic=\csname if#1\endcsname false\else true\fi
    }%
  }\x
}
\apptocmd{\frontmatter}{\SetTocMainMatter{false}}{}{}
\apptocmd{\mainmatter}{\SetTocMainMatter{true}}{}{}
\apptocmd{\appendix}{\SetTocMainMatter{false}}{}{}
\apptocmd{\backmatter}{\SetTocMainMatter{false}}{}{}
\newcommand*{\TocTitleFormat}[1]{%
  \ifTocMainMatter
    #1%
  \else
    \textit{#1}%
  \fi
}
\makeatother

\begin{document}

\frontmatter

\tableofcontents
\chapter{Preface}
\listoftables
\listoffigures

\mainmatter  

\chapter{Introduction}
\chapter{Results and Discussion}
\section{Section}
\section{Another Section}
\chapter{Conclusion}

\appendix

\chapter{My Appendix}
\section{Section in Appendix}
\cite{testa}

\backmatter

\begin{thebibliography}{9}
\bibitem{testa} Author A, Title A, 2012
\end{thebibliography}

\end{document}

Result

share|improve this answer
    
Much to my ignorance, I am still only familiar with higher-level approaches to LaTeX, but your comment on \itshape was key for my understanding. So I changed \textit{#1} to \normalfont\textit{#1} when defining \TocTitleFormat and was able to achieve the desired result. Many thanks. (I've deleted the now irrelevant followup question.) –  nnunes Dec 2 '12 at 17:57
add comment

One possibility using the titletoc package; the etoolbox package was used to patch \frontmatter, \mainmatter, and \appendix, so as to automatically use the corresponding style:

\documentclass{book}
\usepackage[nottoc]{tocbibind}
\usepackage{titletoc}
\usepackage{etoolbox}

\newcommand\frontformat{%
\titlecontents{chapter}[0em]
  {\itshape}{\contentslabel{0em}}
  {}{\normalfont\titlerule*[1pc]{.}\contentspage}}
\newcommand\mainformat{%
\titlecontents{chapter}[1.4em]
  {\addvspace{10pt}\bfseries}{\contentslabel{1.15em}}
  {}{\normalfont\titlerule*[1pc]{.}\bfseries\contentspage}
}
\newcommand\backformat{%
\titlecontents{chapter}[1.5em]
  {\addvspace{10pt}\itshape}{\contentslabel{1.5em}}
  {\hspace*{-1.5em}}{\normalfont\titlerule*[1pc]{.}\contentspage}}

\titlecontents{section}[3.8em]
  {}{\contentslabel{2.3em}}
  {\hspace*{-2.3em}}{\titlerule*[1pc]{.}\contentspage}

\apptocmd{\frontmatter}{\frontformat}{}{}
\apptocmd{\mainmatter}{\mainformat}{}{}
\apptocmd{\appendix}{\backformat}{}{}

\begin{document}

\frontmatter

\tableofcontents
\chapter{Preface}
\listoftables
\listoffigures

\mainmatter

\chapter{Introduction}
\chapter{Results and Discussion}
\section{Section}
\section{Another Section}
\chapter{Conclusion}

\appendix

\chapter{My Appendix}
\cite{testa}

\backmatter

\begin{thebibliography}{9}
\bibitem{testa} Author A, Title A, 2012
\end{thebibliography}

\end{document}

enter image description here

share|improve this answer
    
Exactly what I was looking for. Thank you. May I further suggest that you replace the lines \chapter*{Preface} and \addcontentsline{toc}{chapter}{Preface} by \chapter{Preface} in your solution? The \frontmatter command already turns off chapter numbering. Plus hyperref deslikes \addcontentsline. –  nnunes Nov 27 '12 at 13:59
    
@nnunes yes, I was doing exactly that and other minor changes in the spacing; I've updated my answer. –  Gonzalo Medina Nov 27 '12 at 14:02
    
My previous remark on hyperref and \addcontentsline was incorrect. Since hyperref 2009/11/25 v6.79h \phantomsection is no longer necessary when using the starred version of sectioning commands, see .../44088/when-do-i-need-to-invoke-phantomsection. –  nnunes Dec 1 '12 at 17:02
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.