LaTeX forum ⇒ GeneralHow to create an appendix TOC ? [solved]

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

How to create an appendix TOC ? [solved]

Postby Skiron » Fri Jul 25, 2008 1:52 pm

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:
  1. \documentclass[a4paper]{article}
  2. \usepackage[toc,page,header]{appendix}
  3.  
  4. \begin{document}
  5. \tableofcontents % How to limit this TOC to main document sections ????
  6. \newpage
  7.  
  8. \section{First}
  9. First content.
  10. \section{Second}
  11. Second content.
  12.  
  13. \newpage
  14. \appendix
  15. \appendixpage
  16. % How to insert here a TOC concerning only the appendix sections ????
  17.  
  18. \section{Appendix First}
  19. Appendix first content.
  20. \section{Appendix Second}
  21. Appendix second content.
  22.  
  23. \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...)

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

User avatar
Skiron
Posts: 4
Joined: Fri Jul 25, 2008 1:28 pm

Postby Skiron » Fri Jul 25, 2008 5:03 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 !!

  1. \documentclass[a4paper]{article}
  2. \usepackage[toc,page,header]{appendix}
  3. \usepackage{minitoc}
  4.  
  5. % Make the "Part I" text invisible
  6. \renewcommand \thepart{}
  7. \renewcommand \partname{}
  8.  
  9.  
  10. \begin{document}
  11. \doparttoc % Tell to minitoc to generate a toc for the parts
  12. \faketableofcontents % Run a fake tableofcontents command for the partocs
  13.  
  14. \part{} % Start the document part
  15. \parttoc % Insert the document TOC
  16.  
  17. \section{First}
  18. First content.
  19. \section{Second}
  20. Second content.
  21.  
  22. \newpage
  23. \appendix
  24. \addcontentsline{toc}{section}{Appendix} % Add the appendix text to the document TOC
  25. \part{Appendix} % Start the appendix part
  26. \parttoc % Insert the appendix TOC
  27.  
  28. \section{Appendix First}
  29. Appendix first content.
  30. \section{Appendix Second}
  31. Appendix second content.
  32.  
  33. \end{document}


Note that 3 compilations are needed to the minitoc package.

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

Postby gmedina » Fri Jul 25, 2008 5:10 pm

Hi,

I would suggest you to use the titletoc package instead. I will use your initial code to give an example:
  1. \documentclass[a4paper]{article}
  2. \usepackage[page,header]{appendix}
  3. \usepackage{titletoc}
  4. \usepackage{lipsum}
  5.  
  6. \begin{document}
  7. \startcontents[sections]
  8. \printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}}
  9. \newpage
  10.  
  11. \section{First}
  12. \lipsum[1-6]
  13. \subsection{One one}
  14. \lipsum[1-6]
  15. \section{Second}
  16. \lipsum[1-6]
  17. \subsection{Two one}
  18. \lipsum[1-6]
  19.  
  20. \newpage
  21. \appendix
  22. \appendixpage
  23.  
  24. \startcontents[sections]
  25. \printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}}
  26.  
  27. \section{Appendix First}
  28. \lipsum[1-6]
  29. \section{Appendix Second}
  30. \lipsum[1-6]
  31.  
  32. \end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

User avatar
Skiron
Posts: 4
Joined: Fri Jul 25, 2008 1:28 pm

Postby Skiron » Fri Jul 25, 2008 6:39 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:
  1. \documentclass[a4paper]{article}
  2. \usepackage{hyperref}
  3. \usepackage[page,header]{appendix}
  4. \usepackage{titletoc}
  5. \usepackage{lipsum}
  6.  
  7. ...


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:
  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesPackage{sample}[2008/07/25]
  3.  
  4. \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
  5. \ProcessOptions
  6. \LoadClass{article}
  7.  
  8. \RequirePackage{hyperref}
  9.  
  10. \endinput


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


And, in this case, there is an error while compiling:
  1. ! LaTeX Error: Something's wrong--perhaps a missing \item.
  2. See the LaTeX manual or LaTeX Companion for explanation.
  3. Type H <return> for immediate help.
  4. ...
  5. 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 ?

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

Postby gmedina » Fri Jul 25, 2008 9:28 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:
  1. \NeedsTeXFormat{LaTeX2e}
  2. \ProvidesPackage{sample}[2008/07/25]
  3.  
  4. \DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
  5. \ProcessOptions
  6. \LoadClass{article}
  7.  
  8. \RequirePackage{titletoc}
  9. \RequirePackage{hyperref}
  10.  
  11. \endinput

Then you will have no problems with
  1. \documentclass[a4paper]{sample}
  2. \usepackage[page,header]{appendix}
  3. \usepackage{lipsum}
  4.  
  5. \begin{document}
  6. \startcontents[sections]
  7. \printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}}
  8. \newpage
  9.  
  10. \section{First}
  11. \lipsum[1-6]
  12. \subsection{One one}
  13. \lipsum[1-6]
  14. \section{Second}
  15. \lipsum[1-6]
  16. \subsection{Two one}
  17. \lipsum[1-6]
  18.  
  19. \newpage
  20. \appendix
  21. \appendixpage
  22.  
  23. \startcontents[sections]
  24. \printcontents[sections]{l}{1}{\setcounter{tocdepth}{2}}
  25.  
  26. \section{Appendix First}
  27. \lipsum[1-6]
  28. \section{Appendix Second}
  29. \lipsum[1-6]
  30.  
  31. \end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...

User avatar
Skiron
Posts: 4
Joined: Fri Jul 25, 2008 1:28 pm

Postby Skiron » Sat Jul 26, 2008 11:29 am

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

Postby karpathos2 » Tue Aug 23, 2016 10:05 am

Hi guys,

I have the same problem as skiron but with documentclass 'report' instead of 'article'
with 'chapters' instead of 'sections'.
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.

User avatar
Johannes_B
Site Moderator
Posts: 4109
Joined: Thu Nov 01, 2012 4:08 pm

Postby Johannes_B » Sat Aug 27, 2016 10:39 am

  1. \documentclass[a4paper]{report}
  2. \usepackage{titletoc}
  3. \usepackage{hyperref}
  4. \usepackage[page,header]{appendix}
  5. \usepackage{lipsum}
  6.  
  7. \begin{document}
  8. \startcontents[chapters]
  9. \printcontents[chapters]{l}{1}{\setcounter{tocdepth}{1}}
  10. \newpage
  11.  
  12. \chapter{First}
  13. \lipsum[1-6]
  14. \section{One one}
  15. \lipsum[1-6]
  16. \chapter{Second}
  17. \lipsum[1-6]
  18. \section{Two one}
  19. \lipsum[1-6]
  20.  
  21. \newpage
  22. \appendix
  23. \appendixpage
  24.  
  25. \startcontents[chapter]
  26. \printcontents[chapter]{l}{0}{\setcounter{tocdepth}{1}}
  27.  
  28. \chapter{Wombat}
  29. \lipsum[1-6]
  30. \chapter{Capybara}
  31. \lipsum[1-6]
  32.  
  33. \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.


Return to “General”

Who is online

Users browsing this forum: No registered users and 0 guests