定理 用阿拉伯数字表示,定理 中的 \phantomsection 用罗马数字表示

定理 用阿拉伯数字表示,定理 中的 \phantomsection 用罗马数字表示

我使用罗马数字来表示章节和部分,使用阿拉伯数字来表示定理。

当我想引用\phantomsection定理中的引用时,我发现引用会变回阿拉伯数字。我该如何解决这个问题?

\documentclass{report}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\thechapter.\Roman{section}}
\usepackage{amsthm,hyperref}
\newtheorem{theorem}{Theorem}[chapter]
\renewcommand{\thetheorem}{\arabic{chapter}.\arabic{theorem}}
\begin{document}
    \chapter{A}
    \section{A}
    \begin{theorem}
        asdf asdf asd asd asd fasd asd asdf asd asd asd asd a sdfas dsa  as dfasd as dfas df asd a dfsda \phantomsection\label{LABEL}$Ax=b$.
    \end{theorem}
    I want \ref{LABEL} to be \thesection. Could not understand why redefining \textbackslash thetheorem affects \textbackslash thesection.
\end{document}

答案1

A\label通常是指最后一个\refstepcounter应用的计数器在同一范围内

\label通常不建议在远离计数器“refstepped”的地方发出,因为参考是不可预测的。

该命令\phantomsection实际上与部分无关。之所以选择这个名字,是因为它最常见的用途是模拟部分命令的存在,但它只是为超链接设置一个锚点。

我建议定义您的特殊标签命令:

\documentclass{report}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\thechapter.\Roman{section}}
\usepackage{amsthm,hyperref}

\newtheorem{theorem}{Theorem}[chapter]
\renewcommand{\thetheorem}{\arabic{chapter}.\arabic{theorem}}

\makeatletter
\newcommand{\seclabel}[1]{%
  \@bsphack
  \csname phantomsection\endcsname
  \begingroup
  \let\@bsphack\relax\let\@esphack\relax % we don't want them here
  \edef\@currentlabel{\thesection}%
  \label{#1}%
  \endgroup
  \@esphack
}
\makeatother

\begin{document}

\chapter{A}

\section{A}

\begin{theorem}
asdf asdf asd asd asd fasd asd asdf asd asd asd asd a sdfas dsa  
as dfasd as dfas df asd a dfsda \seclabel{LABEL}$Ax=b$.
\end{theorem}

I want \ref{LABEL} to be \thesection. 

\end{document}

在此处输入图片描述

答案2

我认为您的真正目的是将给定的内联公式变成超目标,以便读者可以通过“单击”文档中其他位置适当构建的超链接从文档的其他位置“跳转”到该公式。

如果是这种情况,则该\phantomsection指令不是适合该工作的工具。相反,请查看包提供的\hypertarget和宏。\hyperrefhyperref

\documentclass{report}
\usepackage{hyperref}
\begin{document}
    \noindent
    Once upon a time. Once upon a time. Once upon a time. Once upon a time. 
    Once upon a time. Once upon a time. Once upon a time. Once upon a time.
    \hypertarget{emc2}{$E=mc^2$}.
    Once upon a time. Once upon a time. Once upon a time. Once upon a time.
    Once upon a time. Once upon a time. Once upon a time. Once upon a time.
    
    \bigskip\noindent
    Once upon a time. Once upon a time. Once upon a time. Once upon a time. 
    Once upon a time. Once upon a time. Once upon a time. Once upon a time.
    \hyperlink{emc2}{An inline formula}.
    Once upon a time. Once upon a time. Once upon a time. Once upon a time.
    Once upon a time. Once upon a time. Once upon a time. Once upon a time.
\end{document}

\hypertarget请注意和的第一个参数hyperref必须相同。

还请注意,内联公式是不是与方程编号或任何其他计数器变量有意义地相关联。

答案3

\phantomsection 与节无关,它仅设置匿名锚点。标签的打印布局仅取决于 的位置\label

\label您可以通过移动定理环境后面来获得想要的输出:

\documentclass{report}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\thechapter.\Roman{section}}
\usepackage{amsthm,hyperref}
\newtheorem{theorem}{Theorem}[chapter]
\renewcommand{\thetheorem}{\arabic{chapter}.\arabic{theorem}}
\begin{document}
    \chapter{A}
    \section{A}
    \begin{theorem}
        asdf asdf asd asd asd fasd asd asdf asd asd asd asd a sdfas dsa  as dfasd as dfas df asd a dfsda \phantomsection$Ax=b$.
    \end{theorem}\label{LABEL}
    I want \ref{LABEL} to be \thesection. Could not understand why redefining \textbackslash thetheorem affects \textbackslash thesection.
\end{document}

但更安全的是使用两个标签,一个用于数字,一个用于锚点:

\documentclass{report}
\renewcommand{\thechapter}{\Roman{chapter}}
\renewcommand{\thesection}{\thechapter.\Roman{section}}
\usepackage{amsthm,hyperref}
\newtheorem{theorem}{Theorem}[chapter]
\renewcommand{\thetheorem}{\arabic{chapter}.\arabic{theorem}}
\begin{document}
    \chapter{A}
    \section{A}\label{section}
    \begin{theorem}
        asdf asdf asd asd asd fasd asd asdf asd asd asd asd a sdfas dsa  as dfasd as dfas df asd a dfsda \phantomsection\label{position}$Ax=b$.
    \end{theorem}
    I want \hyperref[position]{\ref*{section}} to be \thesection. Could not understand why redefining \textbackslash thetheorem affects \textbackslash thesection.
\end{document}

相关内容