在章节标题后添加点(脚本文档)

在章节标题后添加点(脚本文档)

我对添加到文档章节的数字有疑问:数字后面没有点,例如“2 Theory”而不是“2. Theory”。我尝试在章节标题前添加一个点,但结果看起来像“2 . Theory”。我也尝试过,\documentclass[a4paper,11pt,numbers=endperiod]{scrreprt}%\renewcommand{\thechapter}{\arabic{chapter}.}两者都在每个数字后都添加了一个点,甚至“1.1. Title”也添加了一个点,而我想要的是“1.1 Title”。

我的文档如下所示:

    \documentclass[a4paper,11pt]{scrreprt}

    \usepackage[utf8]{inputenc}
    \usepackage[ngerman]{babel}
    \usepackage[T1]{fontenc}
    \graphicspath{{img/}}
    \usepackage{fancyhdr}
    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    \usepackage{caption}
     \usepackage{textcomp}

    \addtokomafont{section}{\small}
    \addtokomafont{subsection}{\small}
    \addtokomafont{subsubsection}{\small}


\begin{document}
\include{theory}
\include{experiment}
\end{document}

答案1

如果章节、小节等不应在编号后加点,请使用选项numbers=noenddot。在章节编号后添加点的一种可能性是

\usepackage{xpatch}
\xpatchcmd\chapterformat{\autodot}{.}{}{\PatchFailed}

\DeclareTOCStyleEntry[
  entrynumberformat=\entrynumberwithdot
]{chapter}{chapter}
\newcommand*\entrynumberwithdot[1]{\def\autodot{.}#1}

示例(附有补充说明):

\documentclass[
  %a4paper,11pt,% default
  numbers=noenddot% default value: autoenddot
]{scrreprt}
%\usepackage[utf8]{inputenc}% needed with older TeX distributions
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage{graphicx}% <- added
\graphicspath{{img/}}
\usepackage{fancyhdr}% it is suggested to use package scrlayer-scrheadings
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{caption}% maybe you can use KOMA-Script commands?
\usepackage{textcomp}

\RedeclareSectionCommands[
  font=\small
]{section,subsection,subsubsection}


\usepackage{xpatch}
\xpatchcmd\chapterformat{\autodot}{.}{}{\PatchFailed}

\DeclareTOCStyleEntry[
  entrynumberformat=\entrynumberwithdot
]{chapter}{chapter}
\newcommand*\entrynumberwithdot[1]{\def\autodot{.}#1}

\usepackage{blindtext}% only for dummy text in the MWE

\begin{document}
\tableofcontents
\Blinddocument
\end{document}

答案2

您可以使用 koma 选项

numbers=enddot

所以第一行将是

  \documentclass[a4paper,11pt,numbers=enddot]{scrreprt}

编辑:

这也将设置章节编号后的点数。

您可能想要选择:删除标题编号中的最后一个点

这是专门针对 KOMA-Script 的解决方案

答案3

这应该适用于每一个documentclass,它基于我的回答这里

\documentclass[a4paper,11pt]{scrreprt}

    \usepackage[utf8]{inputenc}
    \usepackage[ngerman]{babel}
    \usepackage[T1]{fontenc}
    %\graphicspath{{img/}}
    \usepackage{fancyhdr}
    \usepackage{lmodern}
    \usepackage[T1]{fontenc}
    \usepackage{caption}
     \usepackage{textcomp}

    \addtokomafont{section}{\small}
    \addtokomafont{subsection}{\small}
    \addtokomafont{subsubsection}{\small}

\let\oldchapter\chapter
\makeatletter
\def\chapter{%
\def\thechapter{\arabic{chapter}.}%
\@ifstar{\@Starred}{\@nonStarred}%
}
\def\@Starred{%
\@ifnextchar[%
{\GenericWarning{}{Warning: A starred section can not have parameters. I am going to ignore them!}\@StarredWith}%
{\@StarredWithout}%
}      
\def\@StarredWith[#1]#2{%
\oldchapter*{#2}%
\def\thechapter{\arabic{chapter}}%
}
\def\@StarredWithout#1{
\oldchapter*{#1}%
\def\thechapter{\arabic{chapter}}%
}
\def\@nonStarred{%
\@ifnextchar[%
{\@nonStarredWith}%
{\@nonStarredWithout}%
}
\def\@nonStarredWith[#1]#2{%
\oldchapter[#1]{#2}%
\def\thechapter{\arabic{chapter}}%
}
\def\@nonStarredWithout#1{%
\oldchapter{#1}%
\def\thechapter{\arabic{chapter}}%
}
\makeatother

\usepackage{blindtext}% only for dummy text in the MWE
\begin{document}
\tableofcontents
\Blinddocument
\end{document}

添加是为了能够帮助其他文档类别的人,或者甚至是为了满足 OP 的请求(如果他希望documentclass以后能够更改)。

相关内容