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.

I'd like to have in my report a table of contents from introduction to conclusion and another between the conclusion and the first annexe. This latter only for annexes :

- Table of contents
    - 1. Intro
    - 2. Chapter 1
    - ...
    - 20. Conclusion
- 1. Intro
- 2. Chapter 1
- ...
- 20. Conclusion
- SECOND TABLE OF CONTENTS
    - Annexe 1
    - Annexe n
- Annexe 1
- Annexe n

I know we can add annexes to the table of contents using :

\addcontentsline{toc}{chapter}{Annexes}

but is there a way to name a TOC like :

\tableofcontents{TOC1}

and use it to specify which one we want to add contents line :

\addcontentsline{toc}{chapter}{Annexes}{TOC1}

Thank you for your help.

share|improve this question

2 Answers 2

up vote 16 down vote accepted

yes article defines

\newcommand\tableofcontents{%
    \section*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toc}%
    }

so you could define

\newcommand\tableofcontentsA{%
    \section*{\contentsname
        \@mkboth{%
           \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
    \@starttoc{toca}%
    }

then use

\addcontentsline{toca}{chapter}{Annexes}

instead of

\addcontentsline{toc}{chapter}{Annexes}

This will store the headings in a filename with extension .tocA and input that file at the point where you use \tableofcontentsA. Note as there are @ in the command names the definition needs to be in a package file or between \makeatletter \makeatother

If your annexes are using sectioning commands that are internally writing to the .toc file so that you can not easily just write to toca you can redefine the internal writing command to write to toca if passed toc as argument like so:

\let\oldaddtocontents\addtocontents

\def\addtocontents#1{%
   \def\tmpa{#1}%
   \def\tmpb{toc}%
   \ifx\tmpa\tmpb
      \def\tmpa{toca}%
   \fi
   \expandafter\oldaddtocontents\expandafter{\tmpa}}

In the standard classes (and most none standard ones) this will make all the sectioning commands write to .toca from the point of redefinition.

so a complete document

\documentclass{book}

\makeatletter
    \newcommand\tableofcontentsA{%
        \chapter*{\contentsname
            \@mkboth{%
               \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
        \@starttoc{toca}%
        }
\makeatother
\begin{document}
\tableofcontents

\chapter{aa}
\chapter{aaa}

\appendix
\let\oldaddtocontents\addtocontents
\def\addtocontents#1{%
   \def\tmpa{#1}%
   \def\tmpb{toc}%
   \ifx\tmpa\tmpb
      \def\tmpa{toca}%
   \fi
   \expandafter\oldaddtocontents\expandafter{\tmpa}}
\tableofcontentsA

\chapter{bbaa}
\chapter{bbaa}

\end{document}
share|improve this answer
    
One has also to redefine \appendix so that \chapter issues \addcontentsline{tocA}{...}{...} –  egreg May 12 '12 at 10:21
    
@egreg, Yes I wondered about that but the OP indicated he was calling \addcontentsline{toc} explicitly which means you can just change the call. I assumed teh class was using chapter* or something. I'll add a note to the answer. –  David Carlisle May 12 '12 at 10:23
    
Has the first argument of \addcontentsline be the same as \@starttoc? toca/tocA? –  Michaël May 12 '12 at 10:36
    
yes sorry it has to be the same and also you might need \chapter* rather than \section* if based on report or book rather than article. I just added a full working example –  David Carlisle May 12 '12 at 10:41
2  
That's because I just copied the code:-) \contentsname is what is making "Table of Contents" (it makes just "Contents" in book class) so you can just remove that and replace \chapter*{\contentsname} by \chapter*{Table of whatever}. If you are is using a different class, it is worth having a look at its sources and copying \tableofcontents from the class. In my initial answer I copied the one from article.cls which uses \section* in worked example at the end I used the one from book class which uses \chapter* but other classes might use fancier formatting that you could copy. –  David Carlisle May 12 '12 at 13:01

The titletoc package gives another possible (and shorter) solution:

\documentclass{book}
\usepackage{titletoc}

\begin{document}

\startcontents
\printcontents{atoc}{0}{\chapter*{\contentsname}}

\chapter{Test Chapter One}
\chapter{Test Chapter Two}

\appendix

\startcontents
\printcontents{atoc}{0}{\chapter*{Table of Annexes}}
\chapter{Test Appendix One}
\chapter{Test Appendix Two}

\end{document}
share|improve this answer

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.