UPDATE: Sorry I had to delete the original post because I can't add more than 2 links. Okay the root of my problem is this:

\documentclass{report}
\usepackage[toc,page]{appendix}
\usepackage{lipsum}

\begin{document}

\tableofcontents
% Main body
\chapter{Foo 1}
\section{bar 1}
baz bar foo.
\chapter{Foo 2}
\section{bar 2}
foo bar baz.
\section{bar 3}
bar foo baz.

% Appendix
\noappendicestocpagenum
\begin{appendices}
\chapter{First appendix}
\lipsum[1]
\chapter{Second appendix}
\lipsum[1]
\end{appendices}
\end{document}


This code produces the following output in the TOC: There are a few problems with this:

I would like:

1) "Appendices" to be on a 'Chapter' level, as it is now.

2) "A" and "B" to be on a 'section' level, within Appendices. This also means the numbering of the appendices are "A","B",... (NOT "Appendix A","Appendix B",...)

3) The 'section' headings in the appendices to read "Appendix A", "Appendix B" (along with the title of the appendix after the heading)

I've managed to achieve 1 and 3 using subappendices and modifying some commands, but I can't seem to get 2 fully correct. This is what I tried:

\documentclass{report}
\usepackage[toc,page]{appendix}
\usepackage{lipsum}

\begin{document}

\tableofcontents
% Main body
\chapter{Foo 1}
\section{bar 1}
baz bar foo.
\chapter{Foo 2}
\section{bar 2}
foo bar baz.
\section{bar 3}
bar foo baz.

% Appendix
\noappendicestocpagenum
\begin{appendices}
\setcounter{chapter}{1} % To avoid naming problems like .1
\begin{subappendices} % This achieves 2
\renewcommand{\thesection}{Appendix \Alph{section}} % This achieves 3, but screws up 2

\section{First appendix}
\lipsum[1]
\section{Second appendix}
\lipsum[1]
\end{subappendices}
\end{appendices}
\end{document}


and I get the following output:

I have made other attempts to fix this, like with the tocloft package. But the solutions I've seen with this package cannot affect the Appendix section only.

Note: The last output is as close to the desired output I could get. No other options within the appendix package seemed to be able to achieve an effect like this. I just need to fix the numbering as per point 2 into "A","B",...

I hope I have made my problem clear! :) Thanks all!

• Welcome to TeX SX! I would not advise to do it. Each time you re-compile, you'd have to rewrite the toc. There are various tools to obtain what you want, but we need a minimal compilable example, with your preamble. Aug 4, 2016 at 11:13
• As Bernard said: We need a MWE, but I think that the appendix package should be able to achieve this out of the box!
– user31729
Aug 4, 2016 at 12:35
• Hi @ChristianHupfer, I have tried the appendix package, read through the entire documentation but to no avail. Please see my ideal output in the updated post. Thanks! Aug 4, 2016 at 13:54
• @JeremyG: I'll take a look
– user31729
Aug 4, 2016 at 13:56
• @JeremyG: The main cause is the section number width value -- it's too small to have Appendix A inside so the boxes overlap.
– user31729
Aug 4, 2016 at 15:03

Edit: See the version what the O.P. really wanted at the end of the answer!

The number width for the appendix section number is too small, that's why the entries overlap.

This can be cured by adding some extra length (say 40pt) to the \cftsecnumwidth length, but this must written explicitly to the .toc file, i.e. use \addtocontents{toc}{\protect\addtolength....} (see the code for the real version.

The \protect is necessary since \addtolength etc. are fragile commands and would not survive the writing process to the .toc file.

\documentclass{report}
\usepackage{tocloft}

\newlength{\appendixextrasecnumwidth}
\setlength{\appendixextrasecnumwidth}{40pt}
\usepackage[toc,page]{appendix}
\usepackage{lipsum}

\begin{document}

\tableofcontents
% Main body
\chapter{Foo 1}
\section{bar 1}
baz bar foo.
\chapter{Foo 2}
\section{bar 2}
foo bar baz.
\section{bar 3}
bar foo baz.

\begin{appendices}
%  \begin{subappendices}
\renewcommand{\thesection}{\appendixname\ \Alph{section}} % This achieves 3, but screws up 2

\section{First appendix}
\lipsum[1]
\section{Second appendix}
\lipsum[1]
%  \end{subappendices}
\end{appendices}
\end{document}


Update

\documentclass{report}
\usepackage{etoolbox}
\usepackage[toc,page]{appendix}
\usepackage{lipsum}

\makeatletter
\def\@firstarg{}%
\def\@cmp@@{section}%
\makeatother

\begin{document}

\tableofcontents
% Main body
\chapter{Foo 1}
\section{bar 1}
baz bar foo.
\chapter{Foo 2}
\section{bar 2}
foo bar baz.
\section{bar 3}
bar foo baz.

\begin{appendices}
\makeatletter
\let\latex@@seccntformat\@seccntformat%
\def\@seccntformat#1{%
\ifstrequal{#1}{section} {%
\appendixname\ %
}{%
}%
\latex@@seccntformat{#1}%
}
\makeatother
\renewcommand{\thesection}{\Alph{section}} % This achieves 3, but screws up 2
\section{First appendix}
\lipsum[1]
\section{Second appendix}
\lipsum[1]
\end{appendices}
\end{document}

• This is good, but is there a solution that avoids 'Appendix' appearing in the numbering of the Appendix section in TOC? Aug 4, 2016 at 17:25
• @JeremyG: That's in your example already! I thought you want to have it that way?
– user31729
Aug 4, 2016 at 17:26
• I want "Appendix xx" in my main body Appendices, but "xx" in my TOC. In my very first code, it was the correct format ("xx") but the various appendices are their own chapters. I then changed it such that the appendices are sections, but then I had to rename the section headers to "Appendix xx" instead so they show up as "Appendix xx: The first appendix" in the main body, instead of just "A: The first appendix" in the main body. But this caused the number length problem in TOC. Instead of increasing the numwidth in TOC, can I number it with "xx" instead of "Appendix xx"? Aug 4, 2016 at 17:36
• @JeremyG: sigh ...
– user31729
Aug 4, 2016 at 17:37
• @JeremyG: See the update at the end of the answer, please
– user31729
Aug 4, 2016 at 17:48