
내 현재 문서는 다음과 같이 처리됩니다.
1. Some chapter
1.1. Some section
1.1.1. Some subsection
Appendix A.
Some appendix
내가 갖고 싶은 것:
1 Some chapter
1.1 Some section
1.1.1 Some subsection
Appendix A: Some appendix
그래서 주요 부분에서 번호 매기기의 마지막 점을 제거하고 싶습니다. 부록의 경우 점 대신 콜론과 같은 줄의 제목을 원합니다.
사용된 모든 패키지를 포함한 작은 예:
\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}
콜론과 제목을 같은 줄에 어떻게 만들 수 있습니까? 그리고 제목의 마지막 점은 어떻게 제거하나요?
Symbol1의 답변이 작동하지 않습니다. 에러 메시지:
Undefined control sequence. \@makechapterhead ...mdepth >\m@ne \if@mainmatter
\huge \bfseries \@chapapp ... l.108 \chapter{Definition of the Problem}
답변1
다음은 원하는 출력을 얻을 수 있는 방법입니다.KOMA 스크립트클래스:
\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}
점은 의 재정의를 통해 제거되는 \autodot
반면, 부록 형식은 를 호출할 때 \patchcmd
를 통해 수행됩니다 . 최종 패치는 상자의 너비를 에서 까지 조정 합니다 . 이 조정은 를 다루는 ToC의 장 관련 항목에만 적용됩니다 .\@@makechapterhead
\appendix
\numberline
1.5em
6.5em
\l@chapter
etoolbox
패치 기능을 제공합니다.
답변2
KOMA-Script 버전 3.20부터 \DeclareTOCStyleEntry
. 그래서 여기에 새로운 제안이 있습니다:
\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}
세 번 실행하면 다음을 얻을 수 있습니다.
답변3
여기 있어요
\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}
답변4
다음은 @werners 답변과 거의 동일하지만 약간의 차이가 있습니다. 옵션을 사용하면 appendixprefix
접두사를 얻을 수 있습니다부록번호 바로 앞에요. 이는 제목을 같은 줄에 두는 것과 모순됩니다(이것이 구현된 방식입니다). 주요 아이디어는 동일합니다. \@@makechapterhead
마법이 발생하면 패치를 적용하는 것입니다. 처음에는 자동점으로 인쇄할 아무것도 저장하지 않았습니다. 부록이 시작되면 몇 가지 재정의가 이루어집니다. 예를 들어
- 콜론( :
) 을 인쇄하기 위해 자동점 복원
- 줄바꿈을 아무것도 아닌 것으로 패치(공백을 조작할 필요가 없으며 기본 KOMA가 제어됩니다)
- 장 항목을 필요한 양만큼 들여쓰면 의 내용에 따라 동적으로 들여쓰기됩니다 \appendixTocString
. 나중에 그 단어를 인쇄하지 않기로 결정했다면부록, 문자열에서 제거하면 적절하게 들여쓰기됩니다.
\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}