使用 Enumerate 和 Cleveref 进行引用

使用 Enumerate 和 Cleveref 进行引用

我正在努力使用该包设置正确的引用cleveref。我能够获取第二个子层次结构的引用,但是,我无法正确设置第一个层次结构的引用。

正如屏幕截图所示,我怎样才能打印“研究问题 1”而不是像现在这样只打印简单的“1”?有什么想法吗? 在此处输入图片描述

\documentclass{scrbook}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{enumitem}
\usepackage[colorlinks]{hyperref}
\usepackage{cleveref}


\renewcommand{\labelenumii}{\theenumii}
\renewcommand{\theenumii}{\theenumi.\arabic{enumii}.}

\begin{document}

Specifically, this research aims to address the following questions:

\begin{enumerate}[label=\textbf{\itshape Research Question \arabic*},ref=\arabic*, 
leftmargin=*, labelindent=0pt, itemsep=0.5em]

\item \label{rq1} First Question
\begin{enumerate}[label=\textbf{\itshape RQ \theenumii}, leftmargin=1.25em, labelindent=0pt, itemsep=0.5em]
\item \label{rq1.1} First First Subquestion
\item \label{rq1.2} First Second Subquestion
\end{enumerate}
\item \label{rq2} Second Question
\begin{enumerate}[label=\textbf{\itshape RQ \theenumii}, leftmargin=1.25em, labelindent=0pt, itemsep=0.5em]
\item \label{rq2.1} Second First Subquestion
\item \label{rq2.2} Second Second Subquestion
\end{enumerate}

\end{enumerate}

% Reference example
Now you can reference sub-questions using cref or aliases:

This text refers to \cref{rq1}

This text refers to \cref{rq1.1} 

This text refers to \cref{rq1.2}



This text refers to \cref{rq2}

This text refers to \cref{rq2.1}

This text refers to \cref{rq2.2}


\end{document}

答案1

我建议您 (a) 使用包的\newlist\setlistenumitem来创建一个定制的两级枚举类环境——rqenumerate如下例所示;(b) 尽量保持指令ref选项\setlist简单;(c) 使用\crefname(和,如果需要\Crefname)指令来塑造基于 cref 的对两个环境级别的交叉引用的外观。这种方法的优点是,它使您能够在使用和rqenumerate时使用多个参数。\cref\Cref

在此处输入图片描述

\documentclass{scrbook}
%%\usepackage[utf8]{inputenc} % that's the default nowadays
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{enumitem}
\usepackage[colorlinks]{hyperref}
\usepackage[nameinlink]{cleveref} % note the 'nameinlink' option

% Set up a bespoke enumerate-like enviroment
\newlist{rqenumerate}{enumerate}{2}
\setlist[rqenumerate,1]{%
    label=\bfseries\itshape Research Question \arabic*.,
    ref=\arabic*,
    leftmargin=*, labelindent=0pt, itemsep=0.5em}
\setlist[rqenumerate,2]{%
    label=\bfseries\itshape RQ \arabic{rqenumeratei}.\arabic*.,
    ref=\arabic{rqenumeratei}.\arabic*,
    leftmargin=1.25em, labelindent=0pt, itemsep=0.25em}

% define the prefix label strings
\crefname{rqenumeratei}{research question}{research questions}
\crefname{rqenumerateii}{RQ}{RQs}
\Crefname{rqenumerateii}{Research question}{Research questions}


\begin{document}
\noindent
Specifically, this research aims to address the following questions:

\begin{rqenumerate}
\item \label{rq1} First Question
  \begin{rqenumerate}
    \item \label{rq1.1} First First Subquestion
    \item \label{rq1.2} First Second Subquestion
  \end{rqenumerate}
\item \label{rq2} Second Question
  \begin{rqenumerate}
    \item \label{rq2.1} Second First Subquestion
    \item \label{rq2.2} Second Second Subquestion
  \end{rqenumerate}
\end{rqenumerate}

% Reference example
\noindent
Now we can cross-reference questions and sub-questions using \verb+\cref+:

\obeylines % just for this example
This text refers to \cref{rq1}.
This text refers to \cref{rq2}.
\Cref{rq1,rq2} examine \dots
This text refers to \cref{rq1.2}.
\Cref{rq1.1,rq1.2,rq2.1,rq2.2} discuss \dots

\end{document} 

相关内容