自动标记列表中的每个项目

自动标记列表中的每个项目

这在某种程度上是对“枚举项列表中的垂直间距“。

请注意,该问题已纳入下面的示例中。

\documentclass{article}

\usepackage{enumitem}

\makeatletter
\def\myitem{%
  \@ifnextchar[ \@myitem{\@noitemargtrue\@myitem[\@itemlabel]}}
  \def\@myitem[#1]{\item[#1]\mbox{}}
\makeatother
\setlist[enumerate,1]{
  wide = 0\parindent,
  listparindent = 0pt,
  label = \textbf{Exercise~\arabic*}
}
\setlist[enumerate,2]{
  wide = 0\parindent,
  listparindent = 0pt,
  label = \textbf{\alph*)}
}

\begin{document}

\noindent \underline{Example code:}
\begin{enumerate}
\myitem
\begin{enumerate}
  \item Something.
  \item Something.
\end{enumerate}
\myitem
\begin{enumerate}
  \item Something.
  \item Something.
\end{enumerate}
\myitem
\begin{enumerate}
  \item Something.
  \item This is exercise~\textbf{3b)}.
\end{enumerate}

\underline{Question:} Can I avoid manually labeling every single \verb|\item| and \verb|\myitem| and then -- somehow -- combine these labels to get the number of both \verb|\item| and \verb|\myitem| in a single reference?

Example: If I write \verb|This is exercise~\ref{3b}| I would like to get the output ``This is exercise~\textbf{3b)}'' without having to put a \verb|\label| after the \verb|\item|.
\end{enumerate}

\end{document}

输出

答案1

自动标签很容易。但它们对于手动引用来说完全没用。

尝试一下此文档然后取消注释该项目并再次编译:

\documentclass{article}
\usepackage{enumitem}
\newcommand\automaticlabel{\label{\theenumi.\theenumii}}
\begin{document}
\begin{enumerate}
\item 
\begin{enumerate}
  %\item I forgot Yellow \automaticlabel
  \item Green \automaticlabel
  \item Red   \automaticlabel
\end{enumerate}
\end{enumerate}

\ref{1.a} refers to Green. \ref{1.b} refers to Red.
\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容