Tag Archives: appendix

Latex add both appendices and annexes

I’m using the appendix package in a latex document to add appendices and have them in my table of contents. I’m also using the hyperref package to get links from the toc to the sections. I wanted to add a further ‘annexes’ part to the document.

This post gave an example of how to use the appendix package to add additional parts of the document with chapters starting from 1 again. It almost worked but in the toc the annex chapters were linked to the appendix chapters (so annex I was linked to appendix A etc). When I printed out the value of @currentHref (what hyperref uses to link to in the toc) in my annex chapters, it was listing them as appendix.A. If I did a renewcommand on theHchapter (hyperref’s counter) after the change to the definition of thechapter, I at least get appendix.I so the roman numerals bit is working. I can’t for the life of me figure out where the ‘appendix’ prefix is coming from as changed the values of appendixname, appendixpagename and appendixtocname. In the end, I just gave up and added an additional \annexname in theHchapter definition. @currentHref ends up as appendix.Annex.I, but at least it’s unique so the links work in the toc. Pretty sure I’m missing something obvious, but at least this works for now:


% Create Roman Numeral Labelled Annexes
\newcommand{\annexname}{Annex}
\makeatletter % treat @ as a letter instead of a control word.
\newcommand\annex{\par
\setcounter{chapter}{0}
\setcounter{section}{0}
\renewcommand\appendixname{Annex}
\renewcommand\appendixpagename{Annexes}
\renewcommand{\appendixtocname}{Annexes}
\gdef\@chapapp{\annexname}
\gdef\thechapter{\@Roman\c@chapter}
\renewcommand{\theHchapter}{\annexname.\thechapter}
\addappheadtotoc
}
\makeatother

and the in the document, something like:


\appendix
\chapter{one}
\chapter{two}

\annex
\chapter{one}
\chapter{two}

Advertisements