在編號段落後縮排文本

在編號段落後縮排文本

我有一份 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 para 的其餘部分使用懸掛命令,使其與其餘部分保持一致的縮排文字。

或是其他東西 ....

但到目前為止,這超出了我的 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.5cm; 4) 減少\textwidth1.5cm(與 合併\hoffset,右邊距不變); 5) 將紙寬減少 1.5 厘米,以適應\hoffset修改。

我指出這種方法有相關的缺點,這些缺點在 MWE 下面的圖中可以觀察到。頁眉/頁腳發生了移動,這意味著與 OP 的原始代碼相比​​,居中頁碼現在向右移動了 0.75 公分。

OP 表示這種方法適合他/她的需要,並且只需要增加一個\begin{addmargin}環境。由於我不確定 OP 可能在哪裡放置了額外的代碼,因此我沒有嘗試將其插入到我的 MWE 中。

請注意,雜散的上標標記^已從環境中的 OP 程式碼中刪除align*(每行刪除一個),以便於編譯。該程式碼是在 XeLaTeX 中編譯的,儘管它也在 pdflatex 中編譯。

% -*- 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的原始結果

在此輸入影像描述

我建議的改變

在此輸入影像描述

相關內容