使用动态标签引用

使用动态标签引用

我有一个包含多个条件的列表,其中包含一个参数,我想在条件的标签中明确包含该参数。但是,我还想在文本后面引用每个条件的定义(参数固定)。(这有点难以描述,但如果您查看下面的代码,应该会清楚我的意思。)

可以使用 enumitem (或一些其他希望兼容的包)来实现这一点吗?

妈妈:

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{enumitem}
\newtheorem*{theorem}{Theorem}
\begin{document}
    Consider the following conditions:
    \begin{enumerate}[label=(\roman{*})$_n$]
        \item
        \label{item:first_condition}
        Some condition
        \item
        \label{item:second_condition}
        Some other conditon.
    \end{enumerate}
    
    How I would imagine I could type it:
    \begin{theorem}
        \ref{item:first_condition}[7] holds.
    \end{theorem}
    \begin{theorem}
        If \ref{item:second_condition}[n] holds, then \ref{item:first_condition}[n+2] holds.
    \end{theorem}
    
    How I would like it to look like:
    \begin{theorem}
        (i)$_7$ holds.
    \end{theorem}

    \begin{theorem}
        If (ii)$_n$ holds, then (i)$_{n+2}$ holds.
    \end{theorem}
\end{document}

答案1

您可以在 enumitem 中分别设置标签和输出ref,同时使用labelref\begin{enumerate}。这可用于显示n在标签中,但不在参考文献中。这样您就可以通过主数字引用方程式并添加自己的下标。

现在,您可以使用命令定义一个带有两个参数(方程和下标)的单独引用命令\hyperref[target label]{link text}

\ref为了避免出现双链接框,您可以禁用使用星号形式的链接( \ref*),并为组合标签\hyperref创建链接框(或使用的颜色链接)。\usepackage[colorlinks]{hyperref}

梅威瑟:

\documentclass{article}
\usepackage{amsthm}
\usepackage{hyperref}
\usepackage{enumitem}
\newcommand{\nref}[2]{\hyperref[#1]{\ref*{#1}$_{#2}$}}
\newtheorem*{theorem}{Theorem}
\begin{document}
    Consider the following conditions:
    \begin{enumerate}[label=(\roman{*})$_n$,ref=(\roman*)]
        \item
        \label{item:first_condition}
        Some condition
        \item
        \label{item:second_condition}
        Some other conditon.
    \end{enumerate}
    
    How I would imagine I could type it:
    \begin{theorem}
        \nref{item:first_condition}{7} holds.
    \end{theorem}
    \begin{theorem}
        If \nref{item:second_condition}{n} holds, then \nref{item:first_condition}{n+2} holds.
    \end{theorem}
    
    How I would like it to look like:
    \begin{theorem}
        (i)$_7$ holds.
    \end{theorem}

    \begin{theorem}
        If (ii)$_n$ holds, then (i)$_{n+2}$ holds.
    \end{theorem}
\end{document}

结果:

在此处输入图片描述

相关内容