如何更改自定义目录中附录的章节名称

如何更改自定义目录中附录的章节名称

我有一个基于的定制目录这个问题

但是我想在目录中获得“附录 A”而不是“章节 A”,如下图所示: 在此处输入图片描述

我提供了我正在做的事情的 MWE:

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

我已尝试添加\renewcommand\chaptername{Anexo},但它只会更改相应页面上的章节名称,而不会更改目录中的章节名称。

答案1

一致地使用\chapapp而不是\chaptername\appendixname或 capitulo 等固定单词。通常,构造文档的命令会注意\chapapp扩展到所需的任何内容。

我建议进行以下更改:

  • 删除线条

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

    在该行之后\usepackage{appendix}

  • 添加线条

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

    之后\addto\captionsspanish{。请注意,应该读入Anexo的定义\appendixname,而不是Anexos

  • \titlecontents命令中,替换capitulo\chapapp

  • 在 中\renewcommand\chapterformat,替换\usekomafont{chaptername}{\chaptername}\usekomafont{chaptername}{\chapapp}

  • 之后\appendix,更换线路

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

    经过

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

    使用\part*而不是\appendixpage的优点是页面的样式适合其他标题。

在此处输入图片描述

在此处输入图片描述

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

相关内容