首页 > 解决方案 > 对齐编号的段落

问题描述

我正在尝试交叉引用一些编号的段落。我正在使用 \numpar 但第一个总是不对齐。(\项目没有工作)

这是我所做的:

\section{First section}
\subsection*{Subsection1}
\numpar\label{A1} blablabla1
\numpar\label{A2} blablabla2
\numpar\label{A3} blablabla3

\section{Second section}
Statement \ref{A2} = 2 must be true.

这导致:

在此处输入图像描述

我需要对齐所有数字而不影响未编号的段落。我对其他命令持开放态度,而不是 \numpar 如果有的话。任何建议表示赞赏。

标签: latex

解决方案


你为什么不使用enumerate?它是为这种问题而完成的。

\documentclass{article}
\begin{document}
\section{First section}
\subsection*{Subsection1}
\begin{enumerate}
\item \label{A1} blablabla1
\item \label{A2} blablabla2
\item \label{A3} blablabla3
\end{enumerate}
\section{Second section}
Statement \ref{A2} = 2 must be true.

\end{document}

在此处输入图像描述

如果需要,您可以使用 enumitem 包自定义外观。

例如,要增加缩进,加载包,然后开始枚举:

\begin{enumerate}[leftmargin=3cm]`

enumitem 包中有许多选项,它当然可以满足您的需求。

编辑:请注意 \item 将缩进它之后的任何内容。如果您不想要这种行为,请在段落之前关闭枚举。然后您可以重新启动枚举,但您必须注意项目编号(见下文)。

\documentclass{article}
\usepackage{enumitem}
\begin{document}
\section{First section}
\subsection*{Subsection1}
\begin{enumerate}
\item \label{A1} blablabla1

  This paragraph will be indented

\end{enumerate}

But this one will not.

\begin{enumerate}\setcounter{enumi}{1}
  % This insures that item numbering will be coherent
  % set it to the value of the last item
  % If using the enumitem package, there is a simpler way with 'resume'
  % \begin{enumerate}[resume]
\item \label{A2} blablabla2
\item \label{A3} blablabla3
\end{enumerate}

And another non indented par

\section{Second section}
Statement \ref{A2} = 2 must be true.

\end{document}

推荐阅读