GeneralAppendix and index

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Txuko
Posts: 16
Joined: Mon Jan 17, 2011 9:17 am

Appendix and index

Post by Txuko »

If I use:

Code: Select all

\appendix
\cleardoublepage
\chapter{My appendix 1}
\chapter{My appendix 2}
In the index is shown:

A.My appendix 1
B.My appendix 2

And I want to view:
Appendix A. My appendix 1
Appendix B. My appendix 2

In the appendix chapter title the 'Appendix A' label is added OK, but it isn't in the index or the hyperref contents.

Thanks.
Last edited by Txuko on Sat Feb 05, 2011 12:23 am, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Appendix and index

Post by frabjous »

Please post a proper minimal working example.
Txuko
Posts: 16
Joined: Mon Jan 17, 2011 9:17 am

Appendix and index

Post by Txuko »

OK, sorry.

Code: Select all

\documentclass[12pt,a4paper]{book}                                                                                       
\usepackage{appendix}                                                                                                    
\usepackage{hyperref}                                                                                                    
\begin{document}                                                                                                         
                                                                                                                         
\tableofcontents                                                                                                         
                                                                                                                         
\chapter{Intro}                                                                                                          
...                                                                                                                      
\chapter{Concl}                                                                                                          
...                                                                                                                      
\appendix                                                                                                                
\cleardoublepage                                                                                                         
\chapter{My appendix 1}                                                                                                  
...                                                                                                                      
\chapter{My appendix 2}                                                                                                  
...                                                                                                                      
\end{document}
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Appendix and index

Post by frabjous »

Seems like this should be easier, but here's one possible solution, using the tocloft package:

Code: Select all

\documentclass[12pt,a4paper]{book}                                                                                       
\usepackage{appendix}                                                                                                   
\usepackage{hyperref}                                                                                                   
% load tocloft package; leave titles alone
\usepackage[titles]{tocloft}
% put a dot after the chapter number in the toc
\renewcommand{\cftchapaftersnum}{.}
% figure out length that the appendix labels
% in TOC will need to be.
\newlength{\appnums}
\settowidth{\appnums}{\textbf{Appendix B.}}
% throw in an extra half em of padding
\addtolength{\appnums}{0.5em}
\begin{document}                                                                                                         
                                                                                                                         
\tableofcontents                                                                                                         
                                                                                                                         
\chapter{Intro}                                                                                                         
...                                                                                                                     
\chapter{Concl}                                                                                                         
...                                                                                                                     
\appendix                                                                                                               
% add some stuff to the toc to change its behavior
\addtocontents{toc}{\protect\renewcommand{\protect\cftchappresnum}{Appendix\ }}%
\addtocontents{toc}{\protect\setlength{\protect\cftchapnumwidth}{\appnums}}%
\cleardoublepage                                                                                                         
\chapter{My appendix 1}                                                                                                 
...                                                                                                                     
\chapter{My appendix 2}                                                                                                 
...                                                                                                                     
\end{document}
Txuko
Posts: 16
Joined: Mon Jan 17, 2011 9:17 am

Re: Appendix and index

Post by Txuko »

That solves the problem of the index but does not solve the problem with the hyperref contents for the pdf.

Although it seems to work, it give me this error during compilation of the full document (not with the example):
LaTeX Error: Command \c@lofdepth already defined.

This seems complicated. Another solution to the problem would be to create a chapter called Appendices and then put each appendix as a section inside it but I use a book document class and the appendices are defined as chapters and no sections. ¿It's possible to redefine that?

Thank you for all.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Appendix and index

Post by frabjous »

Although it seems to work, it give me this error during compilation of the full document (not with the example):
LaTeX Error: Command \c@lofdepth already defined.
It's impossible to diagnose a problem I cannot reproduce. A minimal working example which actually produces the error would be necessary to tell. The error seems to have something to do with the list of figures?
Txuko wrote:That solves the problem of the index but does not solve the problem with the hyperref contents for the pdf.
Sorry your sample didn't contain the bookmarksnumbered option for hyperref, so it was hard to see the issue here.

I don't know of a good way to reformat the labels in the PDF bookmarks except via more drastic measures, such as skipping the \appendix command altogether and try to recreate its effects in other ways.

So, for example, you could try this:

Code: Select all

\documentclass[12pt,a4paper]{book}                                                                                       
\usepackage{appendix}                                                                                                   
\usepackage[bookmarksnumbered]{hyperref}                                                                                                   
% load tocloft package; leave titles alone
\usepackage[titles]{tocloft}
% put a dot after the chapter number in the toc
\renewcommand{\cftchapaftersnum}{.}
% figure out length that the appendix labels
% in TOC will need to be.
\newlength{\appnums}
\settowidth{\appnums}{\textbf{Appendix B.}}
% throw in an extra half em of padding
\addtolength{\appnums}{0.5em}
\begin{document}                                                                                                         
                                                                                                                         
\tableofcontents                                                                                                         
                                                                                                                         
\chapter{Intro}                                                                                                         
...                                                                                                                     
\chapter{Concl}                                                                                                         
...                                                                                                                     
% Rather than use the \appendix command, we'll manually reset the
% chapter counter and redefine how chapters are labelled
\setcounter{chapter}{0}%
\addtocontents{toc}{\protect\setlength{\protect\cftchapnumwidth}{\appnums}}%
\renewcommand{\thechapter}{Appendix~\Alph{chapter}}%
\renewcommand{\chaptername}{}%
\cleardoublepage                                                                                                         
\chapter{My appendix 1}                                                                                                 
...                                                                                                                     
\chapter{My appendix 2}                                                                                                 
...                                                                                                                     
\end{document}
Txuko
Posts: 16
Joined: Mon Jan 17, 2011 9:17 am

Re: Appendix and index

Post by Txuko »

I didn't know the bookmarksnumbered option. With this option and the previous changes I think the problem is solved.

Thank you very much.
Post Reply