
Mi documento actual se procesa así:
1. Some chapter
1.1. Some section
1.1.1. Some subsection
Appendix A.
Some appendix
Lo que quiero tener:
1 Some chapter
1.1 Some section
1.1.1 Some subsection
Appendix A: Some appendix
Por eso quiero que se eliminen los últimos puntos de la numeración de la parte principal. Para el apéndice, quiero dos puntos en lugar del punto y el título en la misma línea.
Un pequeño ejemplo, incluyendo todos los paquetes utilizados:
\documentclass[appendixprefix=true,11pt,a4paper]{scrreprt}
%The packages used in my document
\usepackage{listings}
\usepackage{mathtools}
\usepackage{graphicx}
\usepackage{enumitem}
\usepackage{chngcntr}
\usepackage[usenames,dvipsnames]{color}
%Appendix definition (Write "Appendix A")
\makeatletter
\newcommand\appendix@numberline[1]{\appendixname\ #1: }
\g@addto@macro\appendix{%
\addtocontents{toc}{
\let\protect\numberline\protect\appendix@numberline}%
}
\makeatother
\begin{document}
\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\appendix
\chapter{Last chapter}
\end{document}
¿Cómo puedo hacer que los dos puntos y el título estén en la misma línea? ¿Y cómo elimino los últimos puntos de los títulos?
La respuesta de Symbol1 no funciona. Mensaje de error:
Undefined control sequence. \@makechapterhead ...mdepth >\m@ne \if@mainmatter
\huge \bfseries \@chapapp ... l.108 \chapter{Definition of the Problem}
Respuesta1
Así es como puede obtener el resultado que busca en elScript KOMAclases:
\documentclass[appendixprefix=true]{scrreprt}
\usepackage{etoolbox}
\makeatletter
\g@addto@macro{\appendix}{%
\patchcmd{\@@makechapterhead}% <cmd>
{\endgraf\nobreak\vskip.5\baselineskip}% <search>
{\hspace*{-.5em}:\space}% <replace>
{}{}% <success><failure>
\patchcmd{\@chapter}% <cmd>
{\addchaptertocentry{\thechapter}}% <search>
{\addchaptertocentry{Appendix~\thechapter:}}% <replace>
{}{}% <success><failure>
\addtocontents{toc}{%
\protect\patchcmd{\protect\l@chapter}% <cmd>
{1.5em}% <search>
{6.5em}% <replace>
{}{}}% <success><failure>
}
\renewcommand{\autodot}{}% Remove all end-of-counter dots
\makeatother
\begin{document}
\tableofcontents
\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\appendix
\chapter{Last chapter}
\end{document}
Los puntos se eliminan mediante una redefinición de \autodot
, mientras que el formateo del Apéndice se realiza mediante una \patchcmd
de \@@makechapterhead
cuando llama \appendix
. El parche final ajusta el ancho del \numberline
cuadro de 1.5em
a 6.5em
. Este ajuste es específico de la entrada relacionada con el capítulo en el ToC, ya que trata sobre \l@chapter
.
etoolbox
proporciona la capacidad de parchear.
Respuesta2
Desde la versión 3.20 de KOMA-Script puedes utilizar \DeclareTOCStyleEntry
. Así que aquí hay una nueva sugerencia:
\documentclass[
%appendixprefix=true,%<- removed
11pt,a4paper,
numbers=noenddot% <- added
]{scrreprt}[2016/05/10]% needs at least version 3.20
\DeclareTOCStyleEntry[
level=\chaptertocdepth,
indent=0pt,
numwidth=2.3em,
dynnumwidth,
linefill=\hfill,
entryformat=\appendixtocformat,
entrynumberformat=\appendixtocnumberformat,
pagenumberformat=\appendixtocpagenumberformat
]{tocline}{appendixchapter}
\newcommand*\appendixtocformat[1]{{\usekomafont{chapterentry}#1}}
\newcommand*\appendixtocnumberformat[1]{{\def\autodot{:}\appendixname\ #1}}
\newcommand*\appendixtocpagenumberformat[1]
{{\usekomafont{chapterentry}\usekomafont{chapterentrypagenumber}#1}}
\usepackage{xpatch}
\xapptocmd\appendix
{%
\renewcommand*{\chapterformat}{%
\mbox{\appendixname{\nobreakspace}\thechapter:%
\IfUsePrefixLine{}{\enskip}}%
}%
\renewcommand*{\chaptermarkformat}{\appendixname\ \thechapter:\enskip}%
\xpatchcmd{\addchaptertocentry}
{\addtocentrydefault{chapter}{#1}{#2}}
{\addtocentrydefault{appendixchapter}{#1}{#2}}%
{}{\PatchFailed}%
}{}{\PatchFailed}
\begin{document}
\tableofcontents
\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\appendix
\chapter{Last chapter}
\end{document}
Ejecute tres veces para obtener:
Respuesta3
Aquí estás
\documentclass{book}
\begin{document}
\makeatletter
\def\@makechapterhead#1{\vspace*{50\p@}{\parindent\z@\raggedright\normalfont\ifnum\c@secnumdepth>\m@ne\if@mainmatter\huge\bfseries\@chapapp\space\thechapter: \fi\fi\interlinepenalty\@M\Huge\bfseries#1\par\nobreak\vskip40\p@}}
\makeatother
\chapter{CHAPI}
\section{SECI}
\subsection{SUBSECTI}
\appendix
\chapter{CHAPII}
\section{SECII}
\subsection{SUBSECTII}
\end{document}
Respuesta4
Lo siguiente es casi lo mismo que la respuesta de @werners, con una ligera diferencia. con la opciónappendixprefix
obtienes el prefijoapéndicejusto antes del número. Esto contradice tener el título en la misma línea (así es como se implementa). La idea principal es la misma, parchear \@@makechapterhead
a medida que ocurre la magia. Al principio no guardé nada para imprimirlo como autopunto. Cuando se inicia el apéndice, se realizan algunas redefiniciones, por ejemplo
- restaurar el punto automático para imprimir dos puntos ( :
)
- parchear el salto de línea a simplemente nada (no es necesario jugar con espacios, el KOMA predeterminado tiene el control)
- Si desea solo el entradas de capítulos sangradas según la cantidad necesaria, se sangra dinámicamente según el contenido de\appendixTocString
. Si decide más adelante no imprimir la palabraApéndice, retírelo de la cuerda y quedará con la sangría adecuada.
\documentclass[
appendixprefix=true,
]{scrreprt}
%The packages used in my document
%\usepackage{scrhack}%patches listings
%\usepackage{listings}
%\usepackage{mathtools}
%\usepackage{graphicx}
%\usepackage{enumitem}
%\usepackage{chngcntr}
%\usepackage[usenames,dvipsnames]{color}
\usepackage{etoolbox}
\renewcommand{\autodot}{}%
\newcommand{\appendixTocString}{\appendixname\space\thechapter\autodot}%
\newlength{\appendixTocStringLength}%
\settowidth{\appendixTocStringLength}{\appendixTocString}%
\addtolength{\appendixTocStringLength}{1.5em}%
\makeatletter%
\gappto{\appendix}{%Doing everything in the appendix%
\patchcmd{\@@makechapterhead}{\endgraf\nobreak\vskip.5\baselineskip}{}{}{}%
\renewcommand{\autodot}{:}%
\addtocontents{toc}{%
\protect\patchcmd{\protect\l@chapter}%
{1.5em}%
{\protect\appendixTocStringLength}%
{}{}}%
\patchcmd{\@chapter}{\addchaptertocentry{\thechapter}{\scr@ds@tocentry}%
}{%
\addchaptertocentry{\appendixTocString}{\scr@ds@tocentry}}{}{}%
}%
\makeatother%
\begin{document}
\tableofcontents
\chapter{First chapter}
\section{First section}
\subsection{First subsection}
\chapter{Second chapter}
\section{Second section}
\subsection{Second subsection}
\appendix
\chapter{In case the chapter title is really long, we need to
make sure that it gets indented properly.}
\section{appendix section}
\subsection{appendix subsection}
\chapter{appendix chapter}
\section{appendix section}
\subsection{appendix subsection}
\chapter{appendix chapter}
\section{appendix section}
\subsection{appendix subsection}
\chapter{appendix chapter}
\section{appendix section}
\subsection{appendix subsection}
\end{document}