Cleveref 用于假设中的项目

Cleveref 用于假设中的项目

考虑下面的代码片段

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{hyperref}

\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  urlcolor=blue,
  naturalnames=false,
  hypertexnames=false,
  breaklinks
}
  
\usepackage[nameinlink]{cleveref}

\newtheorem{hypothesis}{Hypothesis}

\begin{document}
  \begin{hypothesis}\label{hyp:general}
    This is a general hypothesis which contains two subordinate hypotheses
    \begin{enumerate}
      \item \label{hyp:first} First hypothesis
      \item \label{hyp:second} Second hypothesis
    \end{enumerate}
  \end{hypothesis}

This is a reference to the general \cref{hyp:general}, and this to the
second subordinate \cref{hyp:general}.\labelcref{hyp:second}.
  
\end{document}

在此处输入图片描述

一般参考显示正确,但从属假设的交叉引用很糟糕,因为它在假设12

我如何编写命令,使点以与假设完全相同的颜色和样式显示?请注意,我并不是想要一个专门将点涂成蓝色的解决方案。我宁愿想要一个自动继承 hyper setup 命令中指定的颜色的解决方案

谢谢

答案1

hypoenum我建议您(a)在包的帮助下创建一个定制的枚举类型环境enumitem,以及(b)定制对hypoenum环境中枚举项的交叉引用,以(i)在创建交叉引用时使用假设编号作为项目编号的前缀,以及(ii)告知cleveref在环境中创建对枚举项的交叉引用时应使用哪个文本标签hypoenum

单独的评论:我建议在类似定理的环境中使用直立字体来表示枚举。如果您愿意,这可以帮助读者区分什么是内容,什么是结构或“架构”。

在此处输入图片描述

\documentclass{article}
\usepackage{amsmath,amsthm}

\usepackage{hyperref}
\hypersetup{colorlinks=true, allcolors=blue}
\usepackage[nameinlink]{cleveref}

\newtheorem{hypothesis}{Hypothesis}

\usepackage{enumitem} % for \newlist and \setlist macros
\newlist{hypoenum}{enumerate}{1} % associated counter name: 'hypoenumi`.
\setlist[hypoenum]{label=\upshape\arabic*.,
                   ref=\upshape\thehypothesis.\arabic*}
\crefname{hypoenumi}{hypothesis}{hypotheses}

\begin{document}
\begin{hypothesis}\label{hyp:general}
This is a general hypothesis which comprises two subordinated hypotheses:
   \begin{hypoenum}
   \item \label{hyp:first}  First hypothesis
   \item \label{hyp:second} Second hypothesis
   \end{hypoenum}
\end{hypothesis}

\medskip\noindent
This is a cross-reference to the general \cref{hyp:general}, 
and this is one to the subordinated \cref{hyp:second}.
  
\end{document}

答案2

\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{hyperref}

\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  urlcolor=blue,
  naturalnames=false,
  hypertexnames=false,
  breaklinks
}
  
\usepackage[nameinlink]{cleveref}

\newtheorem{hypothesis}{Hypothesis}
\newcommand\refhypo[2]{\hyperref[#1]{\cref*{#1}.}\labelcref{#2}}
\begin{document}
  \begin{hypothesis}\label{hyp:general}
    This is a general hypothesis which contains two subordinate hypotheses
    \begin{enumerate}
      \item \label{hyp:first} First hypothesis
      \item \label{hyp:second} Second hypothesis
    \end{enumerate}
  \end{hypothesis}

This is a reference to the general \cref{hyp:general}, and this to the second 
subordinate \refhypo{hyp:general}{hyp:second}. 
  
 \end{document}

相关内容