在 itemize 环境中对齐文本

在 itemize 环境中对齐文本

我想生成一个“目标”列表(1、2、3……等)作为标签\item,目标文本位于旁边(带有\hspace{Xmm})。对于超出行宽的项目,第二行的对齐方式是不理想的。我希望它齐平。

以下是我目前所掌握的信息:

\documentclass{article}
\usepackage{enumitem}
\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
\begin{document}
\begin{itemize}[leftmargin=*,align=left]
\item[Aim 1] \hspace{10mm} This aim fits nicely on to a single line.
\item[Aim 2] \hspace{10mm} Unfortunately, the details of this aim are such that they will not fit on to a single line. Instead, the text aligns strangely beneath the "Aim 2" item label :(
\end{itemize}
\end{document}

我之前尝试过这个tabbing,结果非常接近所需的输出,但第二个目标不会换到页面宽度:

\documentclass{article}
\usepackage{enumitem}
\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
\begin{document}
\begin{tabbing}
\= \hspace{20mm} \= \\
\> {\bf Aim 1:} \> This aim fits nicely on to a single line.\\[10pt]
\> {\bf Aim 2:} \> Unfortunately, the details of this aim are such that they willnot fit on to a single line. Instead, the text aligns strangely beneath the "Aim 2" item label :(
\end{tabbing}
\end{document}

在此先非常感谢您的帮助/指点。

答案1

另一个选择是使用enumitem包来定义具有所需布局的新列表(选项showframe仅用geometry作视觉指南):

\documentclass{article}
\usepackage{enumitem}
\usepackage[showframe]{geometry}

\newlist{aims}{enumerate}{1}
\setlist[aims,1]{
  label={Aim~\arabic*},
  leftmargin=*,
  align=left,
  labelsep=10mm,
  itemindent=\dimexpr\labelsep+\labelwidth+7pt\relax
}

\begin{document}

\begin{aims}
\item This aim fits nicely on to a single line.
\item The details of this aim are such that they will not fit on to a single line. Now the text aligns with the margin.
\item This aim fits nicely on to a single line.
\item The details of this aim are such that they will not fit on to a single line. Now the text aligns with the margin.
\end{aims}

\end{document}

在此处输入图片描述

由于我不确定所需的对齐方式,因此还有另一种可能性:

\documentclass{article}
\usepackage{enumitem}
\usepackage[showframe]{geometry}

\newlist{aims}{enumerate}{1}
\setlist[aims,1]{
  label={Aim~\arabic*},
  leftmargin=*,
  align=left,
  labelsep=10mm,
}

\begin{document}

\begin{aims}
\item This aim fits nicely on to a single line.
\item The details of this aim are such that they will not fit on to a single line. Now the text aligns with the margin.
\item This aim fits nicely on to a single line.
\item The details of this aim are such that they will not fit on to a single line. Now the text aligns with the margin.
\end{aims}

\end{document}

在此处输入图片描述

答案2

我不确定你到底想要什么,但这里有一个尝试:

\documentclass{article}

\newcounter{myenumi}
\renewcommand{\themyenumi}{(\roman{myenumi})}
\newenvironment{myenumerate}{%
% stuff for beginning of environment goes here
\setlength{\parindent}{0pt}% don't indent paragraphs
\setcounter{myenumi}{0}% restart numbering
\bigskip% skip a line
\renewcommand{\item}{% new definition of item
\par% start a new line
\refstepcounter{myenumi}% advance counter
\makebox[2.5em][l]{\themyenumi}% print counter to width of 3em, aligned to left
}% end of definition of item
}{% at end of environment
\par% start new paragraph
\bigskip% skip a line
\noindent% don't indent new paragraph
\ignorespacesafterend% ignore spaces after environment
}

\pagestyle{empty}

\begin{document}

\noindent Here is some regular text, and I'm going to go on a bit just to see where it wraps and all that.
\begin{myenumerate}
\item Here is the first item which goes on a bit so we can see how it wraps, and it still needs to be longer.
\item Here is another item.
\item Here is yet another item.
\item And this item is going to be much much longer so we can see another example of one that wraps.
\end{myenumerate}
Here is some more regular text, and let's go on a bit here too, just in case it's important how that looks too.

\end{document}

输出

PS 我记不清我最初从哪里得到这个代码了,但它不是我自己的。(如果你能认出这是你写的东西,或者知道谁写过,请告诉我;然后我会删除我的答案,让你发布它。)

相关内容