使用属性进行枚举

使用属性进行枚举

我如何才能轻松地定制\enumerate环境,以便每行不被编号为1.2.等,而是被编号为Property 1.Property 2.等?

答案1

例如,您可以使用该enumitem包来定制enumerate环境。

\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[label=Property \arabic*.,itemindent=*]
  \item First
  \item Second
\end{enumerate}
\end{document}

enumitem还允许您定义自己的列表环境:

\documentclass{article}
\usepackage{enumitem}
\newlist{Properties}{enumerate}{2}
\setlist[Properties]{label=Property \arabic*.,itemindent=*}
\begin{document}
\begin{Properties}
  \item First
  \item Second
\end{Properties}
\end{document}

在此处输入图片描述

设置itemindent*自动计算整个标签所需的宽度。如果不设置,标签将会超出左边距。

如果项目文本太长,一行无法容纳,下一行将从左边距稍微缩进:

在此处输入图片描述

如果您希望第二行与项目文本的开头对齐,请使用leftmargin=*代替itemindent=*。如果您希望第二行不缩进,请使用leftmargin=0pt除了itemindent=*。以下示例总结了这一点:

\documentclass{article}
\usepackage{showframe}
\usepackage{enumitem}
\begin{document}
Just changing the label:
\begin{enumerate}[label=Property \arabic*.]
  \item First, with a very long text that should extend to the next line if I'm not very  much mistaken. 
  \item Second. 
\end{enumerate}

\hrule\medskip

With \verb|itemindent=*|:
\begin{enumerate}[label=Property \arabic*.,itemindent=*]
  \item First, with a very long text that should extend to the next line if I'm not very  much mistaken. 
  \item Second. 
\end{enumerate}

\hrule\medskip

With \verb|leftmargin=*|:
\begin{enumerate}[label=Property \arabic*.,leftmargin=*]
  \item First, with a very long text that should extend to the next line if I'm not very  much mistaken. 
  \item Second. 
\end{enumerate}

\hrule\medskip

With \verb|itemindent=*,leftmargin=0pt|:
\begin{enumerate}[label=Property \arabic*.,itemindent=*,leftmargin=0pt]
  \item First, with a very long text that should extend to the next line if I'm not very  much mistaken. 
  \item Second. 
\end{enumerate}

\end{document}

在此处输入图片描述

相关内容