0

I am using the appendix package to manage my appendix with the \appendices environment, specifically with the options toc and title so that in the text, headings read "Appendix A" whereas in the table of contents it appears as "A" under the heading "Appendix". Because I have more than 26 appendices, I am using alphalph so that the next appendix after Z is named AA. Unfortunately, this leaves insufficient space for the numbering, so that the title starts to overrun it (see image). I tried to use tocloft to increase the size of numwidth via the declaration \cftsetpnumwidth{3em} (the normal width is 2.3em) but this produces the error "@starttoc already defined". I've definitely reached my limits in terms of combining packages.

How can I continue my appendix numbering after Z, whilst retaining the style of including the word "Appendix" in the title but not the TOC, and prevent the TOC from appearing cramped? In the image shown below (appearing on page 2 when generating the minimum working example), I'd like there to be some space between "AA" and "The" (and ideally for the same spacing to be used for the other appendices).

Cramped numbering on page 2 of the output

Minimum example demonstrating the issue:

\documentclass{article}
\usepackage[toc,title]{appendix} %% Manage appendix when using \appendices environment: toc = put header in TOC; title = add the word 'Appendix' in the document before each number
\usepackage{alphalph} %% To number appendices beyond Z

\begin{document}

\tableofcontents\pagebreak

\appendices

\makeatletter \newalphalph{\Alphmult}[mult]{@Alph}{26} \makeatother \renewcommand{\thesection}{\Alphmult{\value{section}}}

\section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \pagebreak % So it doesn't overrun \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{The last appendix}

\end{document}

Ann
  • 529

1 Answers1

1

I don't get an error using tocloft. So I cannot reproduce your issue with an already defined \@starttoc.

But \cftsetpnumwidth is the wrong length. Not the page numbers are the problem, but the with of the section number. So you would have to change \cftsecnumwidth:

\documentclass{article}
\usepackage{tocloft}
\setlength{\cftsecnumwidth}{2.3em}
\usepackage[toc,title]{appendix} %% Manage appendix when using \appendices environment: toc = put header in TOC; title = add the word 'Appendix' in the document before each number
\usepackage{alphalph} %% To number appendices beyond Z

\begin{document}

\tableofcontents\pagebreak% NOTE: \pagebreak here is wrong. It should be either \clearpage or \newpage or better be removed.

\appendices

\makeatletter \newalphalph{\Alphmult}[mult]{@Alph}{26} \makeatother \renewcommand{\thesection}{\Alphmult{\value{section}}}

\section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \pagebreak % So it doesn't overrun \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{The last appendix}

\end{document}

enter image description here

See page 9 (section 2.3) of the tocloft manual for more information about \cftXnumwidth and the name you have to use for X.

As an alternative to using tocloft you can patch \l@section. The original code in article.cls for setting the width reserved for the section number of the ToC entry is: \setlength\@tempdima{1.5em}. So you could use:

\documentclass{article}
\usepackage[toc,title]{appendix} %% Manage appendix when using \appendices environment: toc = put header in TOC; title = add the word 'Appendix' in the document before each number
\usepackage{alphalph} %% To number appendices beyond Z

\usepackage{xpatch} \makeatletter \xpatchcmd{\l@section}{% \setlength@tempdima{1.5em}% }{% \setlength@tempdima{2.3em}% }{}{\PatchFailure} \makeatother

\begin{document}

\tableofcontents

\appendices

\makeatletter \newalphalph{\Alphmult}[mult]{@Alph}{26} \makeatother \renewcommand{\thesection}{\Alphmult{\value{section}}}

\section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \pagebreak % So it doesn't overrun \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{The last appendix}

\end{document}

The result would be the same as above.

But because, usually you would also like to change the indent of the subsection and the subsubsection entries. And maybe you would also like to change the number width of these entries. So using tocloft and \setlength{\cftsubsecindent}{…}` etc. could be favorably.

Another completely different suggestion would be to use package tocbasic instead of tocloft. It provides the feature to detect the needed width of the number automatically:

\documentclass{article}
\usepackage[toc,title]{appendix} %% Manage appendix when using \appendices environment: toc = put header in TOC; title = add the word 'Appendix' in the document before each number
\usepackage{alphalph} %% To number appendices beyond Z

\usepackage{tocbasic} \DeclareTOCStyleEntry[dynnumwidth]{tocline}{section}% automatically detect the number width

\begin{document}

\tableofcontents

\appendices

\makeatletter \newalphalph{\Alphmult}[mult]{@Alph}{26} \makeatother \renewcommand{\thesection}{\Alphmult{\value{section}}}

\section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \pagebreak % So it doesn't overrun \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{An appendix} \section{The last appendix}

\end{document}

This needs as least three LaTeX runs to result in:

using tocbasic

See section 15.3 of one of the KOMA-Script manuals for more information aboute \DeclareTOCStyleEntry.

There are several more packages to manipulate the ToC.

cabohah
  • 11,455
  • Thanks! I applied your first suggestion and it worked, I guess I misidentified which space I needed to expand. Specifically, I added the following to the preamble: \usepackage{tocloft} \setlength{\cftsecnumwidth}{2.3em}

    The error I got (and still get) is "Package tocloft Warning: @starttoc has already been redefined; tocloft bailing out. on input line 1156." but this is on my actual document rather than the minimum example. Since the output looks good I'm going to ignore it.

    Your comment concerning \pagebreak was also noted and I made the correction.

    – Ann Jul 30 '23 at 19:48