
Meu documento atual é processado assim:
1. Some chapter
1.1. Some section
1.1.1. Some subsection
Appendix A.
Some appendix
O que eu quero ter:
1 Some chapter
1.1 Some section
1.1.1 Some subsection
Appendix A: Some appendix
Então, quero que os últimos pontos da numeração sejam removidos da parte principal. Para o apêndice, quero dois pontos em vez do ponto e do título na mesma linha.
Um pequeno exemplo, incluindo todos os pacotes usados:
\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}
Como posso fazer os dois pontos e o título na mesma linha. E como removo os últimos pontos dos títulos?
A resposta do Symbol1 não funciona. Mensagem de erro:
Undefined control sequence. \@makechapterhead ...mdepth >\m@ne \if@mainmatter
\huge \bfseries \@chapapp ... l.108 \chapter{Definition of the Problem}
Responder1
Veja como você pode obter o resultado que procura noScript KOMAAulas:
\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}
Os pontos são removidos por meio de uma redefinição de \autodot
, enquanto a formatação do Apêndice é feita por meio de uma \patchcmd
chamada \@@makechapterhead
de \appendix
. O patch final ajusta a largura da \numberline
caixa de 1.5em
até 6.5em
. Este ajuste é específico para a entrada relacionada ao capítulo no ToC, uma vez que trata de \l@chapter
.
etoolbox
fornece a capacidade de patch.
Responder2
Desde a versão 3.20 do KOMA-Script você pode usar arquivos \DeclareTOCStyleEntry
. Então aqui vai uma nova sugestão:
\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}
Execute três vezes para obter:
Responder3
Olha Você aqui
\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}
Responder4
O seguinte é quase igual à resposta de @werners, com uma pequena diferença. Com a opção appendixprefix
você obtém o prefixoapêndicelogo antes do número. Isto contradiz ter o título na mesma linha (é assim que é implementado). A ideia principal é a mesma, remendando \@@makechapterhead
conforme acontece a mágica. No começo não salvei nada para ser impresso como autodot. Quando o apêndice é iniciado, algumas redefinições são feitas, por exemplo
- restaurar o autodot para imprimir dois pontos ( :
)
- corrigir a quebra de linha para simplesmente nada (não há necessidade de mexer com espaços, o KOMA padrão está no controle)
- Se você quiser apenas o entradas de capítulo recuadas pela quantidade necessária, elas são recuadas dinamicamente pelo conteúdo de \appendixTocString
. Se você decidir posteriormente não imprimir a palavraApêndice, remova-o da string e ele será recuado corretamente.
\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}