
現在のドキュメントは次のように処理されます。
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 回実行すると次のようになります:
答え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}