1

I'm writing my thesis and Appendices have to say “Anexo” before chapter letter. I tried using \usepackage[titletoc]{appendix}, but it didn't work. Also tried to comment command from titlesec and titletoc, but even with this I couldn't make it work.

Here is my MWE:

\documentclass[12pt]{report}

\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel} % pone el idioma en español

\usepackage[titletoc]{appendix}

\renewcommand{\appendixname}{Anexos}
\addto\captionsspanish{\renewcommand{\appendixname}{Anexo}}

\usepackage{titlesec} 
\titleformat{\chapter}[display] 
{\large\bfseries\centering}{\MakeUppercase\chaptertitlename\ \thechapter}{1em}{\MakeUppercase}{} % Cambios en Capitulo

\titleformat{\section}{\large\bfseries}{\thesection.}{1em}{}

\usepackage{titletoc}

\titlecontents{chapter}[0em]
{\vspace{0em}}
{\normalfont\normalsize\contentslabel[\thecontentslabel.]{2em}\uppercase}
{\hspace*{-2em}\uppercase}
{\titlerule*[.75em]{.}\contentspage}

\titlecontents{section}[2em]
{\vspace{0em}}
{\normalfont\normalsize\contentslabel[\thecontentslabel.]{2em}}
{\hspace*{-2em}}
{\titlerule*[.75em]{.}\contentspage}

\usepackage[]{hyperref} % Opción para que aparesca el indice en el pdf

\begin{document}

\tableofcontents

\chapter{text}

\section{text}

\appendix

\chapter{text}
\end{document}

The output is shown in the picture, and I need to print "Anexo A":

enter image description here

Edit 1: I tried adding some code to manually add "Anexo #:" to the titletoc code, without good results:

\appendix

\titlecontents{chapter}[0em]
{\vspace{0em}}
{\normalfont\normalsize\contentslabel[Anexo \thecontentslabel:]{2em}\uppercase}
{\hspace*{-2em}\uppercase}
{\titlerule*[.75em]{.}\contentspage}

\chapter{text}
\chapter{text}

The result:

enter image description here

Is there a way to move the chapter title to the right, to make this solution viable?

4
  • Somewhat related: tex.stackexchange.com/questions/406388/… Actually, one could simplify the solution by using \chapapp instead of \chaptername and/or \appendixname. Commented Sep 23, 2023 at 15:50
  • I tried modifying that solution, but I couldn't get it running to only change the appendix. Could you give my an example on how to use it?
    – JJP
    Commented Sep 25, 2023 at 13:15
  • 1
    I stay away from both titlesec and titiletoc. Commented Sep 26, 2023 at 3:27
  • @JohnKormylo Not just me? I thought I was the only one who couldn't get on with titlesec. (Haven't really experimented with titletoc.)
    – cfr
    Commented Sep 26, 2023 at 4:17

1 Answer 1

4
+50

Borrowing heavily from two other answers on the site

The following seems to do what you want:

\documentclass[12pt]{report}
\usepackage{etoolbox}
\usepackage[spanish]{babel} % pone el idioma en español
\newlength{\toclabelwidth}
\setlength{\toclabelwidth}{2em}
\addto\captionsspanish{\renewcommand{\appendixname}{Anexo}}
\usepackage{titlesec,titletoc}
\setcounter{tocdepth}{3}
\titleformat{\chapter}[display] 
{\large\bfseries\centering}{\MakeUppercase\chaptertitlename\ \thechapter}{1em}{\MakeUppercase}{} % Cambios en Capitulo
\titleformat{\section}{\large\bfseries}{\thesection.}{1em}{}
\makeatletter
\appto\appendix{\addtocontents{toc}{\setlength{\toclabelwidth}{5em}\gdef\protect\@chapapp{\protect\appendixname}}}
\appto\contentsfinish{\gdef\@chapapp{\chaptername}}
\makeatletter
\usepackage{titletoc}
\titlecontents{chapter}
[\toclabelwidth]
{\normalfont\renewcommand\chaptername{}}
{\contentslabel[\@chapapp~\thecontentslabel\quad]{\toclabelwidth}\MakeUppercase}
{}
{\titlerule*[.75em]{.}\contentspage}
\makeatother
\titlecontents{section}
[4em]
{}
{\normalfont\normalsize\contentslabel[\thecontentslabel.]{2em}}
{\hspace*{-2em}}
{\titlerule*[.75em]{.}\contentspage}


\begin{document}

\tableofcontents

\chapter{text}

\section{text}
\subsection{text}

\appendix

\chapter{text}
\section{appendix}
\subsection{appendix}
\end{document}

output of code

6
  • Thanks for your answer! I will try it to see how it works and how to implement it. (don't want to just copy and paste)
    – JJP
    Commented Oct 2, 2023 at 14:40
  • Is there a way to only move “Anexo A TEXT” to the right in TOC, and not all chapters ("1 TEXT”)?. The solution work greats, but I feel that for normal chapters ("1 TEXT”) it takes a lot of the title space. I have TOCDEPTH to 3 (subsubsection in my thesis document), so more space would be great.
    – JJP
    Commented Oct 2, 2023 at 15:20
  • 1
    I don't really see a pleasing way to solve that problem, you don't want the Anexo part to overlap the left margin. Would you want the regular chapter numbers to line up with the left margin and then have a small indent after?
    – Alan Munn
    Commented Oct 2, 2023 at 16:06
  • I would prefer the Chapter number aligned at left margin, while also having "Anexo A" aligned to the left margin. In \titlecontents{chapter}[4.9em], I was expecting a way to change "4.9em", something like: if (anexo) -> 4.9em, else -> othervalue.
    – JJP
    Commented Oct 2, 2023 at 16:13
  • 1
    I've updated the answer so that only the appendix has the larger margin.
    – Alan Munn
    Commented Oct 2, 2023 at 16:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .