以下 MWE 得出了这一结果:
如您所见,我想要很小的方程式编号/标签,但目前它当然不是垂直居中(如规则所示),而是位于基线上。我怎么才能改变这一点呢?也就是说,我想将 (1) 打印得稍微高一点。
(注:我同意不是想要改变的格式\ref, \eqref, \cref
)。
感谢您的想法!
\documentclass[11pt, a4paper]{article}
\usepackage{xcolor}
\usepackage{mathtools}
\usepackage{hyperref}
\usepackage{cleveref}
\newtagform{myTag}{%
\fontsize{5}{0}\sffamily\selectfont\color{green}(}{)}
\usetagform{myTag}
\makeatletter
\renewcommand*{\eqref}[1]{%
\hyperref[{#1}]{%
\textup{(\ref{#1}})
}%
}
\makeatother
\begin{document}
test :
\begin{equation}\label{fun_eq}
x^2+y^2+z^2 + x^2+y^2+z^2 + x^2+y^2+z^2 =
3(x^2+y^2+z^2)
\mathllap{\rule[2.6pt]{12cm}{0.2pt}\hspace{-1.5cm}}
\end{equation}
My favorite equation is \ref{fun_eq}, \eqref{fun_eq}, \cref{fun_eq}
\end{document}
答案1
TeX 基元\vcenter
将框垂直置于数学轴周围(我推测这对应于您经过反复试验绘制的线),而无需猜测正确的数量。
由于括号的高度和深度比数字大,因此垂直居中的概念是相对的:整个标签(包括括号)应该垂直居中,还是只有数字垂直居中?我展示了这两种可能性;我还修复了您对\eqref
位的重新定义。(我更改了颜色以使屏幕截图更清晰;白底绿色难以阅读。)
\documentclass[11pt, a4paper,twocolumn]{article} % twocolumn for smaller snapshot
\usepackage{xcolor}
\usepackage{mathtools}
\usepackage{hyperref}
\usepackage{cleveref}
\newtagform{myTagA}% vertically centered on parentheses
{%
$\vcenter\bgroup
\hbox\bgroup\bgroup % double group to avoid color leaking
\fontsize{5}{0}\sffamily\selectfont\color{blue}%
(%
}{%
)%
\egroup\egroup
\egroup$%
}
\newtagform{myTagB}% vertically centered on number
{%
$\vcenter\bgroup
\hbox\bgroup\bgroup % double group to avoid color leaking
\fontsize{5}{0}\sffamily\selectfont\color{blue}%
\smash{(}%
}{%
\smash{)}%
\egroup\egroup
\egroup$%
}
\renewcommand*{\eqref}[1]{%
\hyperref[{#1}]{%
\textup{(\ref*{#1}})%
}%
}
\begin{document}
test : \usetagform{myTagA}
\begin{equation}\label{fun_eq}
\mathrlap{\rule[2.6pt]{5cm}{0.2pt}}
a + b = c
\end{equation}
My favorite equation is \ref{fun_eq}, \eqref{fun_eq}, \cref{fun_eq}
test : \usetagform{myTagB}
\begin{equation}
\mathrlap{\rule[2.6pt]{5cm}{0.2pt}}
a + b = c
\end{equation}
\end{document}
以下是方程式数字的更详细快照:
答案2
这是一个使用的解决方案environ
:
\usepackage{environ}
\NewEnviron{LiftBox}{\raisebox{.3em}{\BODY}}
\newtagform{myTag}{%
\fontsize{5}{0}\sffamily\selectfont\color{green}\begin{LiftBox}(}{)\end{LiftBox}}
\usetagform{myTag}
完整示例:
\documentclass[11pt, a4paper]{article}
\usepackage{xcolor}
\usepackage{mathtools}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{environ}
\NewEnviron{LiftBox}{\raisebox{.3em}{\BODY}}
\newtagform{myTag}{%
\fontsize{5}{0}\sffamily\selectfont\color{green}\begin{LiftBox}(}{)\end{LiftBox}}
\usetagform{myTag}
\makeatletter
\renewcommand*{\eqref}[1]{%
\hyperref[{#1}]{%
\textup{(\ref{#1}})
}%
}
\makeatother
\begin{document}
test :
\begin{equation}\label{fun_eq}
x^2+y^2+z^2 + x^2+y^2+z^2 + x^2+y^2+z^2 =
3(x^2+y^2+z^2)
\mathllap{\rule[2.6pt]{12cm}{0.2pt}\hspace{-1.5cm}}
\end{equation}
My favorite equation is \ref{fun_eq}, \eqref{fun_eq}, \cref{fun_eq}
\end{document}