동적 태그로 참조

동적 태그로 참조

매개변수가 포함된 여러 조건 목록이 있는데 조건 태그에 매개변수를 명시적으로 포함하고 싶습니다. 그러나 각 조건의 정의(매개변수가 고정된 상태)는 나중에 본문에서 참조하고 싶습니다. (설명하기가 조금 어렵지만 아래 코드를 보면 무슨 뜻인지 명확해지기를 바랍니다.)

enumitem(또는 다른 호환 가능한 패키지)을 사용하여 이를 수행할 수 있습니까?

Mwe:

\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

의 및 키를 ref모두 사용하여 enumitem에서 레이블과 출력을 별도로 설정할 수 있습니다 . 이는 다음을 표시하는 데 사용될 수 있습니다.labelref\begin{enumerate}N라벨에는 있지만 참조에는 없습니다. 이를 통해 주요 숫자로 방정식을 참조하고 자신만의 첨자를 추가할 수 있습니다.

이제 명령을 사용하여 방정식과 아래 첨자라는 두 개의 인수를 사용하여 별도의 참조 명령을 정의할 수 있습니다 \hyperref[target label]{link text}.

\ref이중 링크 상자를 방지하려면 별 모양( \ref*) 을 사용하기 위한 링크를 비활성화 하고 결합된 레이블에 대한 \hyperref링크 상자(또는 색상 링크)를 생성 할 수 있습니다.\usepackage[colorlinks]{hyperref}

MWE:

\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}

결과:

여기에 이미지 설명을 입력하세요

관련 정보