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.

In a book documentclass I would like to have an appendix which appears in the table of contents at the part level. The TOC should look like this:

Preface
Part title
  Chapter title
  Chapter title
Part title
  Chapter title
  Chapter title
Appendix: Some title
Bibliography
Index

I know how to include the bibliography and the index with \addcontentsline{toc}{part}{...} and I even know about \phantomsection trick to get it to point to the right place in the PDF.

But how do I convince the appendix to go to the part level of TOC? It goes under chapter of the last part.

I do not care if I make an appendix "by hand", i.e., without using \appendix. By the way, I am using \titlesec to customize chapter and part formatting.

share|improve this question
    
Just to clarify: Do you currently have an appendix (or several appendixes) that are treated as "chapters", and you want to insert an entry in the ToC that says "Appendix" (or "Appendixes") ahead of the appendix-related entries in the ToC? If that's the case, have you considered issuing the command \part*{Appendix} ahead of the appendix material? Please advise. –  Mico Apr 13 '13 at 8:02
    
Welcome to TeX.sx! –  Peter Jansson Apr 13 '13 at 8:12
    
There is a single appendix, but I would like it to appear in the part part of toc. I am currently using \appendix followed by chapter, but I don't care about what I use. I would just like the appendix not to be included in "Part 2" of the book (like bibliography, which I included in the toc by hand so I could control where in the toc appears, but appendix puts itself in the toc). –  Andrej Bauer Apr 13 '13 at 8:59
    
\part*{Appendix} is not good because it creates a whole page saying just "Appendix". I want the appendix to look like a chapter, not a part, but it should appear in the TOC at the part level. –  Andrej Bauer Apr 13 '13 at 9:18

1 Answer 1

Since you have only one appendix, a "one shot hack" should be sufficient:

\documentclass{book}

\usepackage{etoolbox}
\makeatletter
\newcommand{\appchapter}[1]{%
  \begingroup
  \patchcmd{\@chapter}
   {\addcontentsline{toc}{chapter}}
   {\addcontentsline{toc}{part}}
   {}{}
  \patchcmd{\@chapter}
   {\addcontentsline{toc}{chapter}}
   {\addcontentsline{toc}{part}}
   {}{}
  \chapter{#1}
  \endgroup
}
\makeatother

\begin{document}

\frontmatter
\tableofcontents

\mainmatter

\chapter{Preface}

\part{Part title}
\chapter{Chapter title}
\chapter{Chapter title}

\part{Part title}
\chapter{Chapter title}
\chapter{Chapter title}

\backmatter
\appendix
\appchapter{Appendix: Some title}

\chapter{Bibliography}

\end{document}

enter image description here

share|improve this answer
    
Thanks! One more detail: I use hyperref to generate the table of contents in the PDF file. That is still showing up under chapter. Also, how would I just prevent \appchapter from putting anything at all into TOC? (Then I can put it in by hand.) –  Andrej Bauer Apr 13 '13 at 23:50

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.