左边距的段落编号

左边距的段落编号

我想对大型文档中某些部分的段落进行编号,如下所述https://stackoverflow.com/questions/543208/how-can-one-number-paragraphs-in-latex, 见下文:

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

\N通过将所需的段落放在所需段落之前,这将对我想要的段落进行编号。

但我希望段落编号 [A]、[B]、[C] 位于左边距,而段落则正常缩进。

你有什么建议吗?

答案1

可以使用以下定义来\N实现您想要的:

在此处输入图片描述

\documentclass{article}

\usepackage[nopar]{lipsum}% Just for this example

\newcounter{parnum}
\newlength{\parnumwidth}
\setlength{\parnumwidth}{3em}
\newcommand{\N}{%
  \noindent\refstepcounter{parnum}%
  \makebox[0pt][r]{\makebox[\parnumwidth][l]{\textbf{[\Alph{parnum}].}}}%
  \hspace*{\parindent}\ignorespaces}
\setlength{\parindent}{2em}

\begin{document}

\lipsum[1]

\N\lipsum[2]

\lipsum[3]

\end{document}

段落编号放置在边距中,使用“ ”,放置在宽度为 (设置为)\llap的框内。\parnumwidth3em

您还可以考虑使用\marginpar,它允许您以更灵活的方式将内容放置在边距中:

在此处输入图片描述

\documentclass{article}

\reversemarginpar% Keep \marginpar in left margin
\newcounter{parnum}
\newcommand{\N}{%
  \leavevmode\refstepcounter{parnum}%
  \marginpar{\textbf{[\Alph{parnum}].}}}%
\setlength{\parindent}{2em}

\begin{document}

\N Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus maximus tortor id suscipit sodales. 
Aenean dui orci, congue in quam id, venenatis dignissim felis. Proin leo massa, convallis eu purus ut, 
bibendum iaculis odio. Sed et lacinia nibh. Duis rhoncus rhoncus lorem, vel sodales est feugiat id. 
Maecenas consectetur dolor vitae sem elementum tincidunt. Nunc in posuere purus. Sed congue ullamcorper 
felis, eget efficitur eros maximus in. Nam placerat justo risus, mollis fermentum velit tempus vestibulum. 
Vivamus placerat neque eu dolor rhoncus blandit. Ut aliquet enim eget nisl luctus euismod. Vivamus 
laoreet, elit eu aliquet bibendum, \N magna lorem efficitur turpis, ac cursus tellus tellus non magna. 
Nullam justo erat, imperdiet vel diam eu, auctor luctus dui. Fusce eleifend sem a pulvinar suscipit. 
Praesent facilisis, velit eget placerat mollis, magna magna venenatis est, at fringilla nulla purus sed dolor.

\end{document}

如果需要,您可以调整位置。

相关内容