# Appendices in Table of Content (TOC): remove indentation

I'm writing my thesis, and I need to include my appendices in the table of contents (TOC). So, I wrote some code in latex and I got the following result:

The problem is that I don't want my appendices titles have indentation. I need them to be aligned with the Appendice title (ANEXOS) and the other chapters, as you can see in the previous figure. Any advice? Thank you!

This is my MWE:

\documentclass{book}
\usepackage[utf8]{inputenc}
\usepackage[toc,page]{appendix}

\begin{document}
%
\tableofcontents
%
\chapter{Introduction}
\section{Objectives}

\chapter{Chapter 1}
\section{Theory}
%
% Appendix
\renewcommand{\appendixpagename}{Anexos}
\renewcommand{\appendixtocname}{\textbf{ANEXOS}}
\renewcommand{\appendixname}{Anexo}
%
\begin{appendices}
%
\makeatletter
\begingroup
\let\protect\l@chapter\protect\l@section
\let\protect\l@section\protect\l@subsection
}
%
\chapter{Algorithms 1}
\section{RMA}
\chapter{Algorithms 2}
\section{FDBP}
%
\end{appendices}
%
\end{document}


Instead of just copying the ToC handling of sections/subsections into those of chapters/sections, redefine them appropriately with the correct spacing/indentation:

\documentclass{book}

\usepackage[toc,page]{appendix}

\begin{document}

\tableofcontents

\chapter{Introduction}
\section{Objectives}

\chapter{Chapter 1}
\section{Theory}

% Appendix
\renewcommand{\appendixpagename}{Anexos}
\renewcommand{\appendixtocname}{\textbf{ANEXOS}}
\renewcommand{\appendixname}{Anexo}

\begin{appendices}

\makeatletter
\begingroup
% Default definitions of \l@section and \l@subsection in book.cls
% https://www.tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/base/book.cls?view=co
% \newcommand*\l@section{\@dottedtocline{1}{1.5em}{2.3em}}
% \newcommand*\l@subsection{\@dottedtocline{2}{3.8em}{3.2em}}
\protect\renewcommand{\protect\l@chapter}{\protect\@dottedtocline{1}{0pt}{2.3em}}%
\protect\renewcommand{\protect\l@section}{\protect\@dottedtocline{2}{2.3em}{3.2em}}%
}

\chapter{Algorithms 1}
\section{Special algorithms}

\chapter{Algorithms 2}
\end{appendices}

\end{document}

• This answer almost works, but I don't want sections to appear in the TOC, i.e . A.1 Special algorithms, only chapters appear in the TOC. How could I do that? Thanks. Nov 28 '20 at 12:16
• @LuisD.: You'll note that I commented out setting the tocdepth counter to 1. If you uncomment that, anything higher than a sectional unit level of 1 won't appear in the ToC (which includes the newly-defined \section at level 2).
– Werner
Nov 28 '20 at 17:59
• It works! I uncommented that line. Thank you. Nov 30 '20 at 19:25

Just add the titletoc option when you load appendix and remove the code after \begin{appendix}:

\documentclass{book}
\usepackage[toc, page]{appendix}%

\begin{document}
%
\tableofcontents
%
\chapter{Introduction}
\section{Objectives}

\chapter{Chapter 1}
\section{Theory}
%
% Appendix
\renewcommand{\appendixpagename}{Anexos}
\renewcommand{\appendixtocname}{\textbf{ANEXOS}}
\renewcommand{\appendixname}{Anexo}
%
\begin{appendices}
\chapter{Algorithms 1}
\chapter{Algorithms 2}
\end{appendices}
%
\end{document}


• Thank you for your response. Is there any way to show only "A Algorithms 1" instead of "Anexo A Algorithms 1"? I need that format. Regards. Nov 28 '20 at 4:23
• @LuisD.: It seems I misunderstood part of your requirements. You just have to remove the titletoc option. I'll fix my answer in a moment. Nov 28 '20 at 9:19
• that is better, but the chapter titles of the appendices are not in bold case, they are in normal font, as I showed in the figure I attached. I also forgot to include sections in appendices (I'll add them in a moment), and it's necessary that only the chapters appear in the TOC. Your code output both, chapters and sections, in the TOC. Thanks. Nov 28 '20 at 12:33

This does what you want, including only Appendix chapters in the ToC (no sections there).

% appendixprob.tex  SE 572664

\documentclass{book}
\usepackage[toc,page]{appendix}%

\begin{document}
\tableofcontents

\chapter{Introduction}
\section{Objectives}

\chapter{Chapter 1}
\section{Theory}

% Change the Appendix name
\renewcommand{\appendixpagename}{Anexos}
\renewcommand{\appendixtocname}{\textbf{ANEXOS}}
\renewcommand{\appendixname}{Anexo}

\begin{appendices}
%%%% only appendix chapters in the ToC