## LaTeX forum ⇒ General ⇒ How to create an appendix TOC ? [solved]

LaTeX specific issues not fitting into one of the other forums of this category.
Skiron
Posts: 4
Joined: Fri Jul 25, 2008 1:28 pm

### How to create an appendix TOC ? [solved]

Hello,

I'm writting a document with appendices, I use the "appendix" package.
I'd like to have a table of content in the begining of my document with all the section of the document and only the "Appendix" title section (providing the page number where appendix starts) and not the details of the sections in the appendix.

Then, when appendix starts, I'd like another table of content, but this time with only the sections appearing in the appendix.

Here is a MWE:
\documentclass[a4paper]{article}\usepackage[toc,page,header]{appendix} \begin{document}\tableofcontents % How to limit this TOC to main document sections ????\newpage \section{First}First content.\section{Second}Second content. \newpage\appendix\appendixpage% How to insert here a TOC concerning only the appendix sections ???? \section{Appendix First}Appendix first content.\section{Appendix Second}Appendix second content. \end{document}

In this MWE, I don't want the TOC to display "A Appendix First" and "B Appendix Second", but I want them and their page numbers to be displayed in another TOC, after the "Appendices" keyword.

I searched in the minitoc, tocloft, appendix packages (and even some homemade TeX code) but they don't provide me what I want.

I was thinking about modifying the \tableofcontents command so that I can pass as argument the ".toc" file to use to generate the TOC, and I could separate by hand from the original ".toc" file lines for document or for appendix TOCs.
\tableofcontents command could also be changed to automatically stop reading the ".toc" file after the "Appendix" keyword for the Document TOC, and start from there for the Appendix TOC.

Does anybody knows a way to not have to modify this command (because, I'm not sure to have sufficient knowledge to do so) ?

If not, can anybody tell me where I can find the sources of the \tableofcontents command ? (I can have a try to adapt it to my needs...)

Last edited by Skiron on Sat Jul 26, 2008 11:30 am, edited 2 times in total.

Skiron
Posts: 4
Joined: Fri Jul 25, 2008 1:28 pm
Well... I tried to solve my problems, and, in a sense, I did.

I used the minitoc package and I put my document's content in a \part and my appendices in another. With minitoc I can generate one TOC per part, just as I wanted.

But, the part name are displayed in my document and it doesn't make sense in my case. So, I just don't name them (i.e. "\part{}") and I add in the hearder some command to note show the "Part I" text (see the MWE).

Two problems are left (plus one extra which does not concern me):
• There is still a blank line instead of the "Part I Partname" text.
• I'm using hyperref package to have hyperlink in the PDF file, and the parts have a bookmark, but no text, it doesn't look professional (I'm writing a Master Thesis) (not shown in the MWE).
• (the extra problem) This solution doesn't suit people who want use the \part command
.

Anyway, despite this problems, it is a good solution and I'm going to keep it if nobody has a better idea.
Comments for solving my two last problems are welcome !!


Note that 3 compilations are needed to the minitoc package.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Hi,

I would suggest you to use the titletoc package instead. I will use your initial code to give an example:
\documentclass[a4paper]{article}\usepackage[page,header]{appendix}\usepackage{titletoc}\usepackage{lipsum} \begin{document}\startcontents[sections]\printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}}\newpage \section{First}\lipsum[1-6]\subsection{One one}\lipsum[1-6]\section{Second}\lipsum[1-6]\subsection{Two one}\lipsum[1-6] \newpage\appendix\appendixpage \startcontents[sections]\printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}} \section{Appendix First}\lipsum[1-6]\section{Appendix Second}\lipsum[1-6] \end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

Skiron
Posts: 4
Joined: Fri Jul 25, 2008 1:28 pm
Thank you a lot gmedina, that solve the remaining problems and that's perfect... ...on the MWE only unfortunately.

As I said, I'm using the hyperref package, and all is working well when I use it as follows:
\documentclass[a4paper]{article}\usepackage{hyperref}\usepackage[page,header]{appendix}\usepackage{titletoc}\usepackage{lipsum} ...

But, I made my own class which than call the "article" one, let's call it here "sample.cls", with the following WME
sample.cls file:
\NeedsTeXFormat{LaTeX2e}\ProvidesPackage{sample}[2008/07/25] \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}\ProcessOptions\LoadClass{article} \RequirePackage{hyperref} \endinput

Then, the only thing changed on the MWE you gave me is the first line:
\documentclass[a4paper]{sample} ...

And, in this case, there is an error while compiling:
! LaTeX Error: Something's wrong--perhaps a missing \item.See the LaTeX manual or LaTeX Companion for explanation.Type H <return> for immediate help....l.8 ...umberline {A}Appendix First}{7}{appendix.A}

And, in the final document, the TOCs are displayed, but all the remaining sections which should not appears are listed in normal text style.

I tried to pass the "a4paper" option the the hyperref package, (since I think that it is a problem of passing options), but it is still not working. I don't know what else I can do since the same code is working when I am not using my own "sample.cls" class.

This solution was the easiest and cleanest one ! I'd like to use it !! Any idea ?

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
It all comes down to the order in which titletoc and hyperref are loaded.

Refering to your sample class (sample.cls), if you use:
\NeedsTeXFormat{LaTeX2e}\ProvidesPackage{sample}[2008/07/25] \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}\ProcessOptions\LoadClass{article} \RequirePackage{titletoc}\RequirePackage{hyperref} \endinput

Then you will have no problems with
\documentclass[a4paper]{sample}\usepackage[page,header]{appendix}\usepackage{lipsum} \begin{document}\startcontents[sections]\printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}}\newpage \section{First}\lipsum[1-6]\subsection{One one}\lipsum[1-6]\section{Second}\lipsum[1-6]\subsection{Two one}\lipsum[1-6] \newpage\appendix\appendixpage \startcontents[sections]\printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}} \section{Appendix First}\lipsum[1-6]\section{Appendix Second}\lipsum[1-6] \end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

Skiron
Posts: 4
Joined: Fri Jul 25, 2008 1:28 pm
Wonderfull !!!!

It's working perfectly !!
(I don't have a large experience in LaTeX, I didn't think about package order...)

Your solution suits me perfectly ! It is exactly what I was expecting ! Thank you a lot for your (fast) help !!

karpathos2
Posts: 1
Joined: Tue Aug 23, 2016 12:46 am
Hi guys,

I have the same problem as skiron but with documentclass 'report' instead of 'article'
When 'article' is substituted by 'report' in the solution by gmedina, a lot gets destroyed and i wasn't able to fix it. Can anyone adjust this solution so that it would yield the same results? Help greatly appreciated.

Johannes_B
Site Moderator
Posts: 4109
Joined: Thu Nov 01, 2012 4:08 pm
\documentclass[a4paper]{report}\usepackage{titletoc}\usepackage{hyperref}\usepackage[page,header]{appendix}\usepackage{lipsum} \begin{document}\startcontents[chapters]\printcontents[chapters]{l}{1}{\setcounter{tocdepth}{1}}\newpage \chapter{First}\lipsum[1-6]\section{One one}\lipsum[1-6]\chapter{Second}\lipsum[1-6]\section{Two one}\lipsum[1-6] \newpage\appendix\appendixpage \startcontents[chapter]\printcontents[chapter]{l}{0}{\setcounter{tocdepth}{1}} \chapter{Wombat}\lipsum[1-6]\chapter{Capybara}\lipsum[1-6] \end{document}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.