1

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:

appendices_toc_issue

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}
%
\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}
\makeatletter
\addtocontents{toc}{
    \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}
%
\addtocontents{toc}{\endgroup}
\end{appendices}
%
\end{document}
0

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

enter image description here

\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}

%\addtocontents{toc}{\protect\setcounter{tocdepth}{1}}

\makeatletter
\addtocontents{toc}{%
  \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}
\addtocontents{toc}{\endgroup}
\end{appendices}

\end{document}
3
  • 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.
    – Luis D.
    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.
    – Luis D.
    Nov 30 '20 at 19:25
0

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} 

enter image description here

3
  • 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.
    – Luis D.
    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.
    – Bernard
    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.
    – Luis D.
    Nov 28 '20 at 12:33
0

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
\addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
\chapter{Algorithms 1}
\section{First section}
\chapter{Algorithms 2}
\end{appendices}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.