You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LaTeX如何为带独立编号的\paragraph实现悬挂缩进效果

LaTeX 自定义编号段落悬挂缩进实现方案

问题修正点

原有代码存在两个核心问题导致缩进不符合预期:

  • 手动通过\N命令插入编号,没有给段落设置统一的悬挂缩进规则,换行后内容默认顶格,无法和第一行正文对齐
  • 计数器命名存在笔误:定义的是param计数器,\N命令内调用的却是parnum,会触发编译报错

实现逻辑

借助titlesec包的格式定义接口直接配置paragraph层级样式:

  • 固定编号占用的宽度,将段落设置为悬挂缩进模式,缩进值和编号宽度一致
  • 绑定计数器到对应章节层级,进入更高层级章节时自动重置段落计数
  • 无需手动调用编号命令,直接使用\paragraph{}即可自动生成带编号、符合缩进规则的段落

可直接编译的完整代码

\documentclass{article}
\usepackage{a4wide}
\usepackage[english]{babel}
\usepackage{titlesec}

% 定义段落计数器,绑定到subsubsection层级,进入新subsubsection时自动重置
\newcounter{parnum}[subsubsection]

% 配置paragraph格式,实现悬挂缩进
\titleformat{\paragraph}[hang]
{\normalsize\normalfont} % 段落正文字体设置
{\makebox[2.5em][l]{\arabic{parnum}.}} % 固定编号占2.5em宽度,左对齐放置
{0pt} % 编号与正文的额外间距设为0
{}
% 配置paragraph的上下间距
\titlespacing*{\paragraph}{0pt}{1em}{0.5em}

% 章节编号深度设置
\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\section{Scope}  
\paragraph{} The Scope of this document should number each paragraph sequentially, long text wrapping to the second and subsequent lines will align the first character with the first character of the first line of body text, rather than aligning with the page margin or paragraph number.
\begin{itemize}
    \item [a.] List item 1,
    \item [b.] List item 2, and
    \item [...] ...
    \item [n.] List item n.
\end{itemize}
\paragraph{} Second paragraph with numbering, the indent rule applies to all paragraphs regardless of length.
    
\subsection{Intro}
\paragraph{} This is the intro section paragraph, the counter resets automatically when entering a new subsection.
\paragraph{} Intro section second paragraph.
    
\subsubsection{related docs}
\paragraph{} Here is a list of the related docs, the counter resets again when entering a new subsubsection.
\begin{itemize}
    \item [a.] Related document entry
\end{itemize}
\end{document}

参数调整说明

  • 如需调整编号和正文的间距,修改\makebox[2.5em][l]中的宽度值即可,数值越大间距越宽
  • 如果需要段落编号跟随更高层级(比如subsection、section)重置,修改\newcounter{parnum}[subsubsection]方括号内的章节层级名即可
  • 如果需要多级编号(比如1.1.1.1 这种带章节前缀的段落号),只需要修改\theparnum的定义即可,缩进逻辑无需调整

内容的提问来源于stack exchange,提问作者Sarah Jean

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.01 02:39:49