我怎样才能实现以下结果?
\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{enumerate} [label=\bfseries Definition No \arabic*:]
\item \label{df1} Bla bla bla bla
\item \label{df2} bla bla bla
\end{enumerate}
When I refer to the definition using \textbackslash ref\{df1\}, it displays\ref{df1} while I need to write it like as per "definition 1"
\end{document}
答案1
由于您正在使用该enumitem
包,因此最好创建一个自定义的枚举式列表(在下面的示例中称为“dflist”)并使用该cleveref
包的功能来生成交叉引用。
\documentclass{article}
\usepackage{enumitem,lipsum}
\usepackage[colorlinks]{hyperref} % just for this example
\usepackage[nameinlink]{cleveref}
\newlist{dflist}{enumerate}{1} % create a custom enumerate-like list
\setlist[dflist]{ref=\arabic*,
label=\bfseries Definition No \arabic*:,
leftmargin=*}
\crefname{dflisti}{definition}{definitions}
\Crefname{dflisti}{Definition}{Definitions}
\begin{document}
\begin{dflist}
\item \label{df1} \lipsum*[1]
\item \label{df2} \lipsum*[2]
\end{dflist}
When I refer to the definition using \verb+\ref{df1}+ and
\verb+\cref{df1}+, \LaTeX{} displays~\ref{df1} and \cref{df1},
which is exactly what I need.
\end{document}