修复章节标题的缩进

修复章节标题的缩进

我喜欢重新创建官方模板的布局,以便摆脱 Word。因为模板来自政府,所以我必须 1:1 重新创建它。

最后,该文档看起来应如下所示:

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et 
accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata.

1.      First Section Title
        Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
        tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
        vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.

1.1     First Subsection Title
        Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
        tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
        vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.

1.1.1   First Subsubsection Title
        Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
        tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
        vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.

我的主要问题是章节编号和标题之间的间距。所有章节标题都必须以模板定义的固定缩进开始,因此编号和标题之间的间距必须是动态的。使用普通乳胶,titlesec我只能指定一个固定的间距。我也尝试了memoir带有的包hangsecnum,但使用此选项,数字将左对齐,章节编号和标题之间也有固定的间距。

能否提示一下我如何创建这样的布局?

答案1

您可以使用标题安全如下:

\usepackage{calc}%
\usepackage{titlesec}%
\titleformat{\section} {\normalfont\bfseries}{\makebox[3em][l]{\itshape\thesection}}{1em}{}%
\titleformat{\subsection} {\normalfont\bfseries}{\makebox[3em][l]{\itshape\thesubsection}}{1em}{}%
\titleformat{\subsubsection} {\normalfont\bfseries}{\makebox[3em][l]{\itshape\thesubsubsection}}{1em}{}%

\addtolength{\leftskip}{\widthof{\normalfont\bfseries\makebox[4em]{}}}% Indent text

在此处输入图片描述

答案2

\documentclass[a4paper]{article}
\newlength{\texthanging}
\setlength{\texthanging}{2cm}
\makeatletter
\def\@seccntformat#1{\protect\makebox[0pt][r]{%
  \protect\makebox[\texthanging][l]{\csname the#1\endcsname.}}}
%\def\@seccntformat#1{\llap{\hbox to\texthanging{
%  \csname the#1\endcsname.\hfil}}}
\makeatother
\newcommand\hanging{\leftskip=\texthanging}
\newcommand\nohanging{\leftskip=0pt }

\begin{document}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et 
accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata.

\hanging

\section{First Section Title}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.

\subsection{First Subsection Title}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.

\subsubsection{First Subsubsection Title}
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod
tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At
vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren.

\nohanging

Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor
invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et 
accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata.

\end{document}

未注释的版本和注释的版本\@seccntformat是等效的,但注释的版本使用低级命令。

相关内容