1

I have a cutomized table of contents based on this question

But I want to get "Appendix A" instead "Chapter A" in the toc, as happens in this image: enter image description here

I provide a MWE of what I'm doing:

\documentclass[a4paper, oneside]{scrbook} 
\usepackage[utf8]{inputenc}
\usepackage[spanish, es-tabla]{babel}
\usepackage{hyperref}

\usepackage{lipsum}

\usepackage{fancyhdr} %Personalización encabezados y pies \usepackage[usenames,dvipsnames, table,xcdraw]{xcolor} % Colores

%============== MÁRGENES =====================% \usepackage[ inner = 2cm, % Margen interior outer = 2cm, % Margen exterior top = 2cm, % Margen superior bottom= 2.5cm, % Margen inferior headsep = 30pt, footskip = 30 pt, includeheadfoot, % Incluye cabecera y pie de página en los márgenes ]{geometry} %Para los márgenes y tipo de página

%=============== PÁRRAFOS ====================% \usepackage{parskip} \setparsizes{3em}{20pt}{0pt plus 1fil}

%============= GENERACIÓN DE GRÁFICOS ==========% \usepackage{tikz} \usetikzlibrary{shapes.geometric} \usetikzlibrary{calc, arrows, babel} \usepackage{tkz-fct}

%========= NOMBRE ANEXOS ======================% \usepackage{appendix} %ANEXOS \renewcommand{\appendixname}{Anexos} \renewcommand{\appendixtocname}{Anexos} \renewcommand{\appendixpagename}{Anexos}

%=== CUSTOMIZE TABLE OF CONTENTS ===%

\addto\captionsspanish{ \renewcommand{\contentsname} { \centering{Tabla de contenidos}} %Cambiar nombre del índice }

\DeclareOldFontCommand{\sc}{\normalfont\scshape}{@nomath\sc} \usepackage{kpfonts} \definecolor{doc}{RGB}{0,60,110} \usepackage{titletoc} \contentsmargin{0cm}

\titlecontents{chapter}[4.7pc] {\addvspace{30pt}}% {\begin{tikzpicture}[remember picture, overlay]% \draw[fill=doc!30,draw=doc!30] (-4,-.2) rectangle (-0.5,.5);% \pgftext[left,x=-3.5cm,y=0.2cm]{\color{white}\Large\sc\bfseries capítulo\ \thecontentslabel};% \end{tikzpicture} \color{doc!40}\large\sc\bfseries} {\color{doc!40}\large\sc\bfseries} {\color{doc!40};\titlerule;\large\sc\bfseries Página \thecontentspage \begin{tikzpicture}[remember picture, overlay] \draw[fill=doc!25,draw=doc!20] (2pt,0) rectangle (6,0.1pt); \end{tikzpicture}}%

\titlecontents{section}[7.4pc] {\addvspace{1pt}} {\contentslabel[\thecontentslabel]{2.4pc}} {} {\dotfill\small \thecontentspage} [] \titlecontents{subsection}[10pc] {\addvspace{1pt}} {\contentslabel[\thecontentslabel]{2.4pc}} {} {\dotfill\small \thecontentspage} [] \makeatletter

\renewcommand{\tableofcontents}{% \chapter{% \vspace{20\p@}% \begin{tikzpicture}[remember picture, overlay]% \pgftext[right,x=15cm,y=0.2cm]{\color{doc!30}\Huge\sc\bfseries
\contentsname};% \draw[fill=doc!30,draw=doc!30] (11.7,-.75) rectangle (20,1);% \clip (11.7,-.75) rectangle (20,1); \pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge\sc\bfseries \contentsname};% \end{tikzpicture}}% @starttoc{toc}} \makeatother

%========= CAPÍTULOS Y SECCIONES =============% \usepackage{charter}

\addtokomafont{disposition}{\usefont{T1}{qhv}{b}{n}\selectfont\color{doc!40}}

\addtokomafont{chapter}{\fontsize{30pt}{30pt}\selectfont} \newkomafont{chapternumber}{\fontsize{50}{120}\selectfont\color{white}} \newkomafont{chaptername}{\itshape\rmfamily\small\color{white}} \addtokomafont{chapterentry}{\normalcolor}% entrys in tableofcontents not blue

\addtokomafont{section}{\fontsize{14pt}{14pt}\selectfont} \newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\rmfamily\color{white}}

\addtokomafont{subsection}{\fontsize{12pt}{12pt}\selectfont} \newkomafont{subsectionnumber}{\fontsize{16pt}{16pt}\selectfont\rmfamily\color{white}}

\setcounter{secnumdepth}{\subsectionnumdepth}% subsubsection and lower unnumbered

\renewcommand\chapterformat{% \raisebox{-6pt}{\colorbox{doc!40}{% \parbox[b][60pt]{45pt}{\centering% {\usekomafont{chaptername}{\chaptername}}% \vfill{\usekomafont{chapternumber}{\thechapter\autodot}}% \vspace{6pt}% }}}\enskip}

\renewcommand\sectionformat{% \setlength\fboxsep{5pt}% \colorbox{doc!40}{% \parbox{40pt}{\centering\usekomafont{sectionnumber}{\thesection\autodot}}}% \quad% }

\renewcommand\subsectionformat{% \setlength\fboxsep{5pt}% \colorbox{doc!40}{% \parbox{60pt}{\centering\usekomafont{subsectionnumber}{\thesubsection\autodot}}}% \quad% }

\makeatletter \renewcommand\sectionlinesformat[4]{% @hangfrom{\hspace{#2}#3}{#4}% \Ifstr{#1}{section}{% \parskip\z@% \par\nobreak% \Ifstr{#3}{}{% \rule[\dp\strutbox]{\textwidth}{1pt}}{% \hspace{38pt}\rule[\dp\strutbox]{\dimexpr\textwidth-50pt}{1pt}}% }{}% \Ifstr{#1}{subsection}{% \parskip\z@% \par\nobreak% \Ifstr{#3}{}{% \rule[\dp\strutbox]{\textwidth}{1pt}}{% \hspace*{42pt}\rule[\dp\strutbox]{\dimexpr\textwidth-70pt}{1pt}}% }{}% } \makeatother

\begin{document}

\tableofcontents

\chapter{Introducción} \lipsum[2-3] \section{Justificación} \lipsum[2-3] \chapter{Desarrollo} \lipsum[2-5] \section{Propuesta} \lipsum[2-6] \subsection{Planificación} \lipsum[2-3] \chapter{Conclusiones} \lipsum[2-3]

\appendix \renewcommand\chaptername{Anexo} \clearpage \addappheadtotoc \appendixpage \renewcommand\chaptername{Anexo} \chapter{Prueba 1} \chapter{Prueba 2}

\end{document}

I've tried by adding \renewcommand\chaptername{Anexo}, but It only changes the name of the chapter on the respective page and not in TOC.

1 Answers1

1

Use consistently \chapapp instead of \chaptername, \appendixname, or hard-wired words like capitulo. In general, commands structuring the document take care that \chapapp expands to whatever is needed.

I suggest the following changes:

  • Remove the lines

    \renewcommand{\appendixname}{Anexos}
    \renewcommand{\appendixtocname}{Anexos}
    \renewcommand{\appendixpagename}{Anexos}
    

    after the line \usepackage{appendix}.

  • Add the lines

    \renewcommand{\appendixname}{Anexo}
    \renewcommand{\appendixtocname}{Anexos}
    \renewcommand{\appendixpagename}{Anexos}
    

    after \addto\captionsspanish{. Note that it should read Anexo in the definition of \appendixname, not Anexos.

  • In the \titlecontents command, replace capitulo by \chapapp.

  • In \renewcommand\chapterformat, replace \usekomafont{chaptername}{\chaptername} by \usekomafont{chaptername}{\chapapp}.

  • After \appendix, replace the lines

    \renewcommand\chaptername{Anexo}
    \clearpage
    \addappheadtotoc
    \appendixpage
    \renewcommand\chaptername{Anexo}
    

    by

    \part*{\appendixpagename}
    \addappheadtotoc
    \addtocontents{toc}{\let\protect\chapapp\protect\appendixname}
    

    Using \part* instead of \appendixpage has the advantage that the styling of the page fits the other headings.

enter image description here

enter image description here

\documentclass[a4paper, oneside]{scrbook} 
\usepackage[utf8]{inputenc}
\usepackage[spanish, es-tabla]{babel}
\usepackage{hyperref}

\usepackage{lipsum}

\usepackage{fancyhdr} %Personalización encabezados y pies \usepackage[usenames,dvipsnames, table,xcdraw]{xcolor} % Colores

%============== MÁRGENES =====================% \usepackage[ inner = 2cm, % Margen interior outer = 2cm, % Margen exterior top = 2cm, % Margen superior bottom= 2.5cm, % Margen inferior headsep = 30pt, footskip = 30 pt, includeheadfoot, % Incluye cabecera y pie de página en los márgenes ]{geometry} %Para los márgenes y tipo de página

%=============== PÁRRAFOS ====================% \usepackage{parskip} \setparsizes{3em}{20pt}{0pt plus 1fil}

%============= GENERACIÓN DE GRÁFICOS ==========% \usepackage{tikz} \usetikzlibrary{shapes.geometric} \usetikzlibrary{calc, arrows, babel} \usepackage{tkz-fct}

%========= NOMBRE ANEXOS ======================% \usepackage{appendix} %ANEXOS

%=== CUSTOMIZE TABLE OF CONTENTS ===%

\addto\captionsspanish{ \renewcommand{\contentsname} { \centering{Tabla de contenidos}} %Cambiar nombre del índice \renewcommand\appendixname{Anexo} \renewcommand{\appendixtocname}{Anexos} \renewcommand{\appendixpagename}{Anexos} }

\DeclareOldFontCommand{\sc}{\normalfont\scshape}{@nomath\sc} \usepackage{kpfonts} \definecolor{doc}{RGB}{0,60,110} \usepackage{titletoc} \contentsmargin{0cm}

\titlecontents{chapter}[4.7pc] {\addvspace{30pt}}% {\begin{tikzpicture}[remember picture, overlay]% \draw[fill=doc!30,draw=doc!30] (-4,-.2) rectangle (-0.5,.5);% \pgftext[left,x=-3.5cm,y=0.2cm]{\color{white}\Large\sc\bfseries\chapapp\ \thecontentslabel};% \end{tikzpicture} \color{doc!40}\large\sc\bfseries} {\color{doc!40}\large\sc\bfseries} {\color{doc!40};\titlerule;\large\sc\bfseries Página \thecontentspage \begin{tikzpicture}[remember picture, overlay] \draw[fill=doc!25,draw=doc!20] (2pt,0) rectangle (6,0.1pt); \end{tikzpicture}}%

\titlecontents{section}[7.4pc] {\addvspace{1pt}} {\contentslabel[\thecontentslabel]{2.4pc}} {} {\dotfill\small \thecontentspage} [] \titlecontents{subsection}[10pc] {\addvspace{1pt}} {\contentslabel[\thecontentslabel]{2.4pc}} {} {\dotfill\small \thecontentspage} [] \makeatletter

\renewcommand{\tableofcontents}{% \chapter{% \vspace{20\p@}% \begin{tikzpicture}[remember picture, overlay]% \pgftext[right,x=15cm,y=0.2cm]{\color{doc!30}\Huge\sc\bfseries
\contentsname};% \draw[fill=doc!30,draw=doc!30] (11.7,-.75) rectangle (20,1);% \clip (11.7,-.75) rectangle (20,1); \pgftext[right,x=15cm,y=0.2cm]{\color{white}\Huge\sc\bfseries \contentsname};% \end{tikzpicture}}% @starttoc{toc}} \makeatother

%========= CAPÍTULOS Y SECCIONES =============% \usepackage{charter}

\addtokomafont{disposition}{\usefont{T1}{qhv}{b}{n}\selectfont\color{doc!40}}

\addtokomafont{chapter}{\fontsize{30pt}{30pt}\selectfont} \newkomafont{chapternumber}{\fontsize{50}{120}\selectfont\color{white}} \newkomafont{chaptername}{\itshape\rmfamily\small\color{white}} \addtokomafont{chapterentry}{\normalcolor}% entrys in tableofcontents not blue

\addtokomafont{section}{\fontsize{14pt}{14pt}\selectfont} \newkomafont{sectionnumber}{\fontsize{18pt}{18pt}\selectfont\rmfamily\color{white}}

\addtokomafont{subsection}{\fontsize{12pt}{12pt}\selectfont} \newkomafont{subsectionnumber}{\fontsize{16pt}{16pt}\selectfont\rmfamily\color{white}}

\setcounter{secnumdepth}{\subsectionnumdepth}% subsubsection and lower unnumbered

\renewcommand\chapterformat{% \raisebox{-6pt}{\colorbox{doc!40}{% \parbox[b][60pt]{45pt}{\centering% {\usekomafont{chaptername}{\chapapp}}% \vfill{\usekomafont{chapternumber}{\thechapter\autodot}}% \vspace{6pt}% }}}\enskip}

\renewcommand\sectionformat{% \setlength\fboxsep{5pt}% \colorbox{doc!40}{% \parbox{40pt}{\centering\usekomafont{sectionnumber}{\thesection\autodot}}}% \quad% }

\renewcommand\subsectionformat{% \setlength\fboxsep{5pt}% \colorbox{doc!40}{% \parbox{60pt}{\centering\usekomafont{subsectionnumber}{\thesubsection\autodot}}}% \quad% }

\makeatletter \renewcommand\sectionlinesformat[4]{% @hangfrom{\hspace{#2}#3}{#4}% \Ifstr{#1}{section}{% \parskip\z@% \par\nobreak% \Ifstr{#3}{}{% \rule[\dp\strutbox]{\textwidth}{1pt}}{% \hspace{38pt}\rule[\dp\strutbox]{\dimexpr\textwidth-50pt}{1pt}}% }{}% \Ifstr{#1}{subsection}{% \parskip\z@% \par\nobreak% \Ifstr{#3}{}{% \rule[\dp\strutbox]{\textwidth}{1pt}}{% \hspace*{42pt}\rule[\dp\strutbox]{\dimexpr\textwidth-70pt}{1pt}}% }{}% } \makeatother

\begin{document}

\tableofcontents

\chapter{Introducción} \lipsum[2-3] \section{Justificación} \lipsum[2-3] \chapter{Desarrollo} \lipsum[2-5] \section{Propuesta} \lipsum[2-6] \subsection{Planificación} \lipsum[2-3] \chapter{Conclusiones} \lipsum[2-3]

\appendix \part*{\appendixpagename} \addappheadtotoc \addtocontents{toc}{\let\protect\chapapp\protect\appendixname} \chapter{Prueba 1} \chapter{Prueba 2}

\end{document}

gernot
  • 49,614