如何获取 \paragraph 的枚举,但不获取 \section 的枚举

如何获取 \paragraph 的枚举,但不获取 \section 的枚举

我需要\paragraph{xxx}命令输出“§ 1 xxx”,但\section{Abc}输出只有“Abc”,没有编号。有什么帮助吗?谢谢。

答案1

通常\paragraph使用\@startsection计数器secnumdepth来定义是否对单元进行编号。例如,在article.cls您可以找到

    \renewcommand\thesubparagraph {\theparagraph.\@arabic\c@subparagraph}

    \newcommand\paragraph{\@startsection{paragraph}{4}{\z@}%
                                {3.25ex \@plus1ex \@minus.2ex}%
                                {-1em}%
                                {\normalfont\normalsize\bfseries}}

第一个命令将段落编号为 Section.Para,第二个命令设置段落的格式。

您可以修补这些命令,例如

\documentclass{article}
\setcounter{secnumdepth}{0}         % Now sections are not numbered
\renewcommand\theparagraph{\arabic{paragraph}} % delete the section num from \theparagraph
\makeatletter
\renewcommand\paragraph{%
   \refstepcounter{paragraph}%   Manually stepping paragraph counter without consulting secnumdepth
   \@startsection{paragraph}{4}{\z@}%
     {3.25ex \@plus1ex \@minus.2ex}%
     {-1em}%
     {\normalfont\normalsize\bfseries\S~\theparagraph\space}} % Formatting the paragraph
\makeatother

\begin{document}
\section{First section}
\paragraph{First paragraph} Second
\end{document}

相关内容