如何在 LaTeX 中对段落进行编号?

发布于 2024-07-13 18:22:50 字数 1428 浏览 7 评论 0原文

给定一堆段落:

Para. A ...

Para. B ...

Para. C ...

如何让 LaTeX 自动对它们进行编号,即

1. Para. A. ...

2. Para. B. ...

3. Para. C. ...

我看到了以下建议:

\newcounter{parnum}
\newcommand{\N}{%
   \noindent\refstepcounter{parnum}%
    \makebox[\parindent][l]{\textbf{\arabic{parnum}.}}}
% Use a generous paragraph indent so numbers can be fit inside the
% indentation space.
\setlength{\parindent}{2em}

从这里: comp.text.tex: Re: 如何在 LaTeX 中对段落进行编号?

然后在每个要编号的段落前面使用 \N,即

\N Para. A. ...

\N Para. B. ...

\N Para. C. ...

I还看到了对 Sarovarnumberpar,但两者都被称为“不稳定”或“不可预测”,以及诸如“随机断裂”,这让我很警惕。

我想要一些关于什么是最好的行动方案的意见,我认为这是一个值得讨论的话题。

感谢您对此的兴趣和关注。

编辑:我已经尝试过以下方法

\begin{enumerate}
\item Para No. 1
\item Para No. 2
...
\end{enumerate}

,但是它会导致排版问题,特别是因为我散布了章节标题ala。

\begin{enumerate}
\item Para No. 1
\item Para No. 2
\section{Part II}
\item Para No. 5
\item Para No. 6
...
\end{enumerate}

并且部分标题“第二部分”有时会出现在页面的最底部(即它与以下文本不一致)。

Given a bunch of paragraphs:

Para. A ...

Para. B ...

Para. C ...

How can one have LaTeX automatically number them, i.e.

1. Para. A. ...

2. Para. B. ...

3. Para. C. ...

I've seen the following suggested:

\newcounter{parnum}
\newcommand{\N}{%
   \noindent\refstepcounter{parnum}%
    \makebox[\parindent][l]{\textbf{\arabic{parnum}.}}}
% Use a generous paragraph indent so numbers can be fit inside the
% indentation space.
\setlength{\parindent}{2em}

From here: comp.text.tex: Re: How do I number paragraphs in LaTeX?

Then use \N in front of every paragraph-to-be-numbered, i.e.

\N Para. A. ...

\N Para. B. ...

\N Para. C. ...

I've also seen references to Sarovar and numberpar, but both are referred to as "unstable" or "unpredictable", and things like "randomly breaks", which makes me wary.

I'd like some input on what may be the best course of action, here, and I think it's a topic worth some discussion.

Thank you for your interest and attention to this.

EDIT: I've tried the following

\begin{enumerate}
\item Para No. 1
\item Para No. 2
...
\end{enumerate}

However it results in typesetting problems, notably because I am interspersing section headings ala.

\begin{enumerate}
\item Para No. 1
\item Para No. 2
\section{Part II}
\item Para No. 5
\item Para No. 6
...
\end{enumerate}

and the section heading "Part II" will sometimes end up at the very bottom of the page (i.e. it doesn't keep with the following text).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

野却迷人 2024-07-20 18:22:51

此问题的解决方案是使用包 parano,该包由印度特里凡得琅 River Valley Technologies 的 CV Radhakrishnan 编写。

我从以下网页知道这个解决方案
http://www.ub-filosofie.ro/~solcan /wt/gnu/n/np.html

A solution to this problem is the use of the package parano, written by CV Radhakrishnan from River Valley Technologies, Trivandrum, India.

I know this solution from the following webpage
http://www.ub-filosofie.ro/~solcan/wt/gnu/n/np.html

时光清浅 2024-07-20 18:22:50

我认为存在三种可能的解决方案(至少!),它们不涉及滚动您自己的或其他人的宏,具体取决于您想要做什么。

1 如果整个文档都需要编号,请使用 \paragraph,这是一个较低级别的分段命令(如 \chapter、\section、\subsection 等)。

请参阅 LaTeX wikibook 了解更多信息。

\setcounter{secnumdepth}{5}
...
\paragraph{If we want to} do something ... 

(您可能会发现这种杀伤力过大/丑陋,因为它需要节和子节的正确嵌套结构)

请注意,如果您使用回忆录文档类(我毫不犹豫地推荐),则 \setcounter行变为 \maxsecnumdepth{paragraph}

2 如果只是一小段,则使用列表:

\begin{enumerate}
\item Para No. 1
\item Para No. 2
...
\end{enumerate} 

3 或广义列表 (\begin{list}...\end{list{}< /code>) 如果你想调整格式。 除了 LaTeX 指南

I think there are three possible solutions (at least!) which don't involve rolling your own or someone else's macro, depending on exactly what you are trying to do.

1 If the numbering is required throughout the document, use \paragraph, which is a lower-level sectioning command (like \chapter, \section, \subsection, etc.)

See the LaTeX wikibook for more information.

\setcounter{secnumdepth}{5}
...
\paragraph{If we want to} do something ... 

(You may find this overkill/ugly, because it needs a properly nested structure of sections and subsections not to be)

Note that if your using the memoir document class (which I recommend unhesitatingly), the \setcounter line becomes \maxsecnumdepth{paragraph}

2 If it's just a small piece, use a list:

\begin{enumerate}
\item Para No. 1
\item Para No. 2
...
\end{enumerate} 

3 Or a generalized list (\begin{list}...\end{list{}) if you want to tweak the formatting. I haven't immediately been able to find a good online reference for this, other than the piece in A Guide to LaTeX

淤浪 2024-07-20 18:22:50

就我而言,我最终通过重新定义一个像段落一样工作的新宏 \P 来解决这个问题。

\newcounter{paranum}
\newcommand{\P}{\vspace{10pt}\noindent\textbf{\refstepcounter{paranum}\theparanum}\textbf}

要编写一个新的“段落”,我要做的

\P{Paragraph title No. 1} ...text...
...
\P{Paragraph title No. 2} ...text...

是将枚举链接到我使用的部分,

\newcounter{paranum}[section]
\newcommand{\P}{\vspace{10pt}\noindent\textbf{\thesection.\refstepcounter{paranum}\theparanum}\textbf}

我知道这实际上是搞砸了,但最终为我工作。

In my case I ended up solving this by redefining a new macro \P that works like a paragraph.

\newcounter{paranum}
\newcommand{\P}{\vspace{10pt}\noindent\textbf{\refstepcounter{paranum}\theparanum}\textbf}

To write a new "paragraph" I do

\P{Paragraph title No. 1} ...text...
...
\P{Paragraph title No. 2} ...text...

To make the enumeration be linked to the section I use

\newcounter{paranum}[section]
\newcommand{\P}{\vspace{10pt}\noindent\textbf{\thesection.\refstepcounter{paranum}\theparanum}\textbf}

I know that this is actually botched-up but ended up working for me.

游魂 2024-07-20 18:22:50

我相信另一个选择是 ledmac 包。 这是文档中的引用:

普通的 \label、\ref 和 \label \pageref 宏可以在编号文本中使用,并以熟悉的方式操作。 作为示例,这是一种编号方式
编号文本中的段落,然后能够引用段落编号,
除了行号和页码。

\newcounter{para} \setcounter{para}{0}
\newcommand{\newpara}{%
  \refstepcounter{para}%
  \noindent\llap{\thepar. }\quad}
\newcommand{\oldpara}[1]{%
  \noindent\llap{\ref{#1}. }\quad}

\newpara 和 \oldpara 的定义将数字放在左边距中,
该段落的第一行是缩进的。 您现在可以编写如下内容:

\linenummargin{right}
\beginnumbering
\pstart
\newpara\label{P1} A paragraph about \ldots
\pend
  In paragraph~\ref{P1} the author \ldots
\pstart
\oldpara{P1} This has the same
             \edtext{number}{\Afootnote{\ref{P1} is the paragraph, not line}}
  as the first paragraph.
\pend
\endnumbering

但是,我自己从未尝试过这样做。

I believe another option is the ledmac package. Here is a quote from the documentation:

The normal \label, \ref and \label \pageref macros may be used within numbered text, and operate in the familiar fashion. As an example, here is one way of numbering
paragraphs in numbered text, and then being able to refer to the paragraph numbers,
in addition to line and page numbers.

\newcounter{para} \setcounter{para}{0}
\newcommand{\newpara}{%
  \refstepcounter{para}%
  \noindent\llap{\thepar. }\quad}
\newcommand{\oldpara}[1]{%
  \noindent\llap{\ref{#1}. }\quad}

The definitions of \newpara and \oldpara put the numbers in the left margin and
the first line of the paragraph is indented. You can now write things like:

\linenummargin{right}
\beginnumbering
\pstart
\newpara\label{P1} A paragraph about \ldots
\pend
  In paragraph~\ref{P1} the author \ldots
\pstart
\oldpara{P1} This has the same
             \edtext{number}{\Afootnote{\ref{P1} is the paragraph, not line}}
  as the first paragraph.
\pend
\endnumbering

I've never attempted this myself, however.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文