我有以下代码:
\documentclass{article}
\usepackage[top = 2cm, bottom = 1cm, left = 1.5cm, right = 1.5cm, includefoot]{geometry}
\usepackage[italic = true]{derivative}
\usepackage{physics}
\usepackage{tcolorbox}
\definecolor{blizzardblue}{rgb}{0.4, 0.6, 0.8}
\definecolor{bleudefrance}{rgb}{0.19, 0.55, 0.91}
\newcommand{\Emph}[1]{{\bfseries #1}}
\NewDocumentCommand{\bline}{somo}{%
\IfBooleanTF{#1}{
\begin{tcolorbox}[
colback = blizzardblue!30!white,
colframe = blizzardblue!30!white,
]
\setlength{\abovedisplayskip}{0pt}
\begin{flalign*}
\IfValueT{#2}{\text{\Emph{#2}}} && #3 &&
\end{flalign*}
\IfValueT{#4}{\emph{#4}}
\end{tcolorbox}\noindent%
}{
\begin{tcolorbox}[
colback = blizzardblue!30!white,
colframe = blizzardblue!30!white,
]
\setlength{\abovedisplayskip}{0pt}
\begin{flalign}
\IfValueT{#2}{\text{\Emph{#2}}} && #3 &&
\end{flalign}
\IfValueT{#4}{\emph{#4}}
\end{tcolorbox}\noindent%
}}
\usepackage{hyperref}
\newcommand{\eq}[1]{{\hyperref[#1]{eq. ({\color{bleudefrance}\ref*{#1}})}}}
\begin{document}
\bline[Gauss's Law]{
\label{gaussLaw}
\nabla\vdot\vb{E} = \frac{\rho}{\epsilon_0}
}
As you can see in \eq{gaussLaw}, it says "1" instead of "Gauss's Law".
\end{document}
产生
我需要的是:调整代码,使其\eq
给出(产生)“高斯定律”而不是“eq (1)”。注释:\tag
可能不是我要找的解决方案,因为我想要一个等式的数字。我希望能够通过其数字(1)或名称(高斯定律)来引用该等式。我希望我已经解释清楚了。如果需要更多信息,请告诉我。谢谢阅读。
答案1
您可以定义\@currentlabelname
然后使用\nameref
:
\documentclass{article}
\usepackage[top = 2cm, bottom = 1cm, left = 1.5cm, right = 1.5cm, includefoot]{geometry}
\usepackage[italic = true]{derivative}
\usepackage{physics}
\usepackage{tcolorbox}
\definecolor{blizzardblue}{rgb}{0.4, 0.6, 0.8}
\definecolor{bleudefrance}{rgb}{0.19, 0.55, 0.91}
\newcommand{\Emph}[1]{{\bfseries #1}}
\makeatletter
\NewDocumentCommand{\bline}{somo}{%
\def\@currentlabelname{#2}%
\IfBooleanTF{#1}{
\begin{tcolorbox}[
colback = blizzardblue!30!white,
colframe = blizzardblue!30!white,
]
\setlength{\abovedisplayskip}{0pt}
\begin{flalign*}
\IfValueT{#2}{\text{\Emph{#2}}} && #3 &&
\end{flalign*}
\IfValueT{#4}{\emph{#4}}
\end{tcolorbox}\noindent%
}{
\begin{tcolorbox}[
colback = blizzardblue!30!white,
colframe = blizzardblue!30!white,
]
\setlength{\abovedisplayskip}{0pt}
\begin{flalign}
\IfValueT{#2}{\text{\Emph{#2}}} && #3 &&
\end{flalign}
\IfValueT{#4}{\emph{#4}}
\end{tcolorbox}\noindent%
}}
\usepackage{hyperref}
\newcommand{\eq}[1]{{\hyperref[#1]{eq. ({\color{bleudefrance}\ref*{#1}})}}}
\begin{document}
\bline[Gauss's Law]{
\label{gaussLaw}
\nabla\vdot\vb{E} = \frac{\rho}{\epsilon_0}
}
As you can see in \eq{gaussLaw}, it says "1" instead of "Gauss's Law".
\nameref{gaussLaw}
\end{document}