Удалить последнюю точку в нумерации заголовка

Удалить последнюю точку в нумерации заголовка

Мой текущий документ обрабатывается следующим образом:

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

Вот как вы можете получить желаемый результат вКОМА-скриптклассы:

введите описание изображения здесь

\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при \@@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

Следующий ответ почти такой же, как у @werner, с небольшой разницей. С опцией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}

Связанный контент