编号段落后缩进文本

编号段落后缩进文本

我有一份 60 页的文档,其中的章节、小节和段落均已编号。所有段落均已编号。我希望所有文本在已编号的段落后均匀缩进,如下例所示:

1.      Section

1.1     Subsection

1.1.1   Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
        Donec rhoncus non ante faucibus tempus. Quisque ex orci, 
        faucibus vitae magna sed, blandit fermentum massa. 

1.1.2   Some numbered paras interrupted by lists: 
        * Item 1
        * Item 2
        * Item 3
        and some text to finish the paragraph

1.1.2   Some numbered paras interrupted by sets of equations using AMSmath: 

            A = B
            C = D

        and some text to finish the paragraph

目前,我有大约 60 页的文本(包括许多方程式),围绕以下 koma-script 类构建:

% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}


\setcounter{secnumdepth}{4}
\renewcommand\theparagraph{\thesubsection.\arabic{paragraph}}
\newcommand\p{\paragraph{}}
%
%
% make sure paragraphs reset counting at section and subsections
%
\makeatletter
\@addtoreset{paragraph}{subsection}
\@addtoreset{paragraph}{section}
\makeatother
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}
\p \blindtext
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para

% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where 
\begin{align*}
D^_{l} & =  \text{the lower date}  \\
D^_{u} & =  \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$. 
\end{document}

因此,所有文本都返回到左侧边距。如果我可以使用类似 koma-script\addmargin命令的东西从左侧缩进列表和数学,那就太理想了;但要调整\p编号段落命令,使其编号从左侧开始齐平,但用一个方框围绕数字以使其具有标准大小,然后对 \p 段落的其余部分使用悬挂命令,使其与缩进的其余文本对齐。

或者是其他东西 ....

但到目前为止,这超出了我的 LaTeX 技能范围。

答案1

更新:KOMA 脚本版本 3.17(或更新版本)

在 KOMA-Script 版本中,该命令\othersectionlevelsformat已弃用。您必须改用等\sectionformat\subsectionformat因此代码更改为

% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}

\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}

\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\sectionformat{\parbox{\secnumindent}{\thesection\autodot}}
\renewcommand\subsectionformat{\parbox{\secnumindent}{\thesubsection\autodot}}
\renewcommand\subsubsectionformat{\parbox{\secnumindent}{\thesubsubsection\autodot}}
\renewcommand\paragraphformat{\parbox{\secnumindent}{\theparagraph\autodot}}

% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections    
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother
% to reset headwidth and footwidth
\usepackage[
  headwidth=\the\textwidth+\secnumindent:-\secnumindent,
  footwidth=head:-\secnumindent,
  headsepline,% to show the headwidth
  footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para

% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where 
\begin{align*}
D_{l} & =  \text{the lower date}  \\
D_{u} & =  \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$. 
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}

结果和下图一样。

如果这也应该与版本 3.15 和 3.16 兼容,请插入

\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}
\providecommand\sectionformat{}\providecommand\subsectionformat{}
\providecommand\subsubsectionformat{}\providecommand\paragraphformat{}

就在重新定义\sectionformat等等之前


KOMA 脚本版本 3.15 和 3.16

您可以使用新命令\RedeclareSectionCommand\RedeclareSectionCommands并重新定义\othersectionlevelsformat。因此仍然可以通过以下方式引用节号\ref

\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}

\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}

% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections    
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother

要重置原始头宽和脚宽,您可以使用

\usepackage[
  headwidth=\the\textwidth+\secnumindent:-\secnumindent,
  footwidth=head:-\secnumindent,
  headsepline,% to show the headwidth
  footsepline% to show the footwidth
]{scrlayer-scrpage}

在此处输入图片描述

代码:

% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}

\setcounter{secnumdepth}{4}
\newcommand\p{\paragraph{}}

\newcommand\secnumindent{1.5cm}
\RedeclareSectionCommands[indent=-\secnumindent]{section,subsection,paragraph}
\RedeclareSectionCommand[afterskip=0pt,counterwithin=subsection]{paragraph}
\renewcommand\othersectionlevelsformat[3]{\parbox{\secnumindent}{#3\autodot}}

% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
%
% make sure paragraphs reset counting also at sections    
%
\makeatletter
\@addtoreset{paragraph}{section}
\makeatother
% to reset headwidth and footwidth
\usepackage[
  headwidth=\the\textwidth+\secnumindent:-\secnumindent,
  footwidth=head:-\secnumindent,
  headsepline,% to show the headwidth
  footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para

% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where 
\begin{align*}
D_{l} & =  \text{the lower date}  \\
D_{u} & =  \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$. 
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}

KOMA-Script 版本 3.14(或更早版本)

这是另一个建议,使用@Steven 的答案,但重新定义\othersectionlevelsformat而不是\thesection。因此仍然可以通过以下方式引用章节编号\ref

\newcommand\p{\paragraph{}\hspace*{-1em}}

\newcommand\secnumindent{1.5cm}
\renewcommand\othersectionlevelsformat[3]{\makebox[0pt][r]{\parbox{\secnumindent}{#3\autodot}}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}

代码:

% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}

\setcounter{secnumdepth}{4}
\renewcommand\theparagraph{\thesubsection.\arabic{paragraph}}
\newcommand\p{\paragraph{}\hspace*{-1em}}

\newcommand\secnumindent{1.5cm}
\renewcommand\othersectionlevelsformat[3]{\makebox[0pt][r]{\parbox{\secnumindent}{#3\autodot}}}
% from the answer of @Steven:
\addtolength\hoffset{\secnumindent}
\addtolength\textwidth{-\secnumindent}
% to reset headwidth and footwidth
\usepackage[
  headwidth=\the\textwidth+\secnumindent:-\secnumindent,
  footwidth=head:-\secnumindent,
  headsepline,% to show the headwidth
  footsepline% to show the footwidth
]{scrlayer-scrpage}
%
% make sure paragraphs reset counting at section and subsections
%
\makeatletter
\@addtoreset{paragraph}{subsection}
\@addtoreset{paragraph}{section}
\makeatother
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}\label{sec:first}
\p \blindtext
% a reference
\p See \ref{sec:first}
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para

% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where 
\begin{align*}
D_{l} & =  \text{the lower date}  \\
D_{u} & =  \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$. 
\section{Next section}
\subsection{Next subsection}
\p \blindtext
\end{document}

答案2

正如我在评论中建议的那样,将这些行添加到序言中

\let\svthesection\thesection
\def\thesection{\kern-1.5cm\svthesection}
\hoffset=\dimexpr\hoffset + 1.5cm\relax
\textwidth=\dimexpr\textwidth-1.5cm\relax
\paperwidth=\dimexpr\paperwidth -1.5cm\relax

他们所完成的操作是:1)保存 的副本\thesection;2)\thesection在打印出节标题之前,重新定义为将字距向左移动 1.5 厘米;3)进行修改\hoffset以将整个文档向右移动 1.5 厘米;4)将 减少\textwidth1.5 厘米(与 结合\hoffset,右边距保持不变);5)将纸张宽度减少 1.5 厘米,以适应修改\hoffset

我指出这种方法存在一些缺点,这些缺点在 MWE 下方的图中可见。页眉/页脚发生了移动,这意味着与 OP 的原始代码相比,居中的页码现在向右移动了 0.75 厘米。

OP 表示这种方法可以满足他/她的需求,只需要添加一个\begin{addmargin}环境。由于我不确定 OP 可能将附加代码放在哪里,因此我没有尝试将其插入到我的 MWE 中。

请注意,为了便于编译,环境^中 OP 代码中的杂散上标标记已被删除(每行删除一个)。此代码是在 XeLaTeX 中编译的,但它也可以在 pdflatex 中编译。align*

% -*- program: xelatex -*-
\documentclass[english, parskip=full, fontsize=11, DIV12, toc=left, numbers=noenddot]{scrartcl}
\usepackage{babel}
\usepackage{amsmath}
% just so we can see what is going on for now
\usepackage{showframe}
\usepackage{blindtext}
% tighten up spacing of lists
\usepackage{enumitem}
\setlist{noitemsep}


\setcounter{secnumdepth}{4}
\renewcommand\theparagraph{\thesubsection.\arabic{paragraph}}
\newcommand\p{\paragraph{}}
%
%
% make sure paragraphs reset counting at section and subsections
%
\makeatletter
\@addtoreset{paragraph}{subsection}
\@addtoreset{paragraph}{section}
\makeatother

\let\svthesection\thesection
\def\thesection{\kern-1.5cm\svthesection}
\hoffset=\dimexpr\hoffset + 1.5cm\relax
\textwidth=\dimexpr\textwidth-1.5cm\relax
\paperwidth=\dimexpr\paperwidth -1.5cm\relax
%
% AND NOW WE BEGIN
%
\begin{document}
\section{Section}
\subsection {Subsection}
\p \blindtext
% an example numbered paragraph with an embedded list
\p \blindtext
\begin{itemize}
\item Item 1
\item Item 2
\item Item 3
\end{itemize}
and some words at the end of this para

% an example numbered paragraph with a simple equation
\p The period is defined by a pair of days ($D_l$, $D_u$) where 
\begin{align*}
D_{l} & =  \text{the lower date}  \\
D_{u} & =  \text{the upper date}
\end{align*}
and things happen for all days $d$ where $D_l <= d< D_u$. 
\end{document}

OP 的原始结果

在此处输入图片描述

按照我建议的改变

在此处输入图片描述

相关内容