# How to center vertically small (tiny) equation numbered tags?

The following MWE procudes this result:

As you see, I want to have tiny equation numbers/tags, but currently it is not centered vertically of course (as the rule shows), it lies on the baseline. How can I possibly change this? That is, I want to print (1) a bit higher.

(NB: I do not want to change the formatting of \ref, \eqref, \cref though).

\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 :
$$\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}}$$
My favorite equation is \ref{fun_eq}, \eqref{fun_eq}, \cref{fun_eq}
\end{document}


The TeX primitive \vcenter centers boxes vertically around the math axis (corresponding to the line you have drawn with a bit of trial/error, I presume) without having to guess the right amount.

Since the parentheses have a larger height and a depth than the numbers, the concept of vertical centering is relative: should the whole tag (including parentheses) be vertically centered, or only the number? I show both possibilities; I have also fixed your redefinition of \eqref a bit. (I've changed the color to make the screenshot clearer; green on white is difficult to read.)

\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}
$$\label{fun_eq} \mathrlap{\rule[2.6pt]{5cm}{0.2pt}} a + b = c$$
My favorite equation is \ref{fun_eq}, \eqref{fun_eq}, \cref{fun_eq}
test : \usetagform{myTagB}
$$\mathrlap{\rule[2.6pt]{5cm}{0.2pt}} a + b = c$$

\end{document}


Here a closer snapshot of the equation numbers:

• OK, I see, I should have used something like \mathrlap{\vcenter{ \rule{12cm}{0.2pt} }}  ;-). Thanks! Mar 12, 2021 at 17:30
• @Watson Not quite. \vcenter expects vertical material but \rule is a LaTeX macro which expands to a rule in horizontal mode, so the result wouldn't be correct. You need \mathrlap{\vcenter{\hrule width 12cm}}. Mar 12, 2021 at 17:37
• Thanks for taking the time to explain to me these things! So hrule is used in "vertical mode"? (I think the "h" in "hrule" is just reminds us that hrule prints a horizontal line, which has apparently nothing to do with horizontal mode). Mar 12, 2021 at 17:48
• @Watson Yes, that's a very strange thing in TeX: \hrule is a vertical mode comand, and \vrule works in horizontal mode. The idea is that if you do \vbox{\hrule\hbox{...}} then the \hrule will automatically stretch to the natural width of the \vbox if no explicit parameters are given. Of course, if you declare a larger height than with the rule will look like a vertical one, but in TeX's eyes that's irrelevant. Mar 12, 2021 at 17:52
• Thanks for your explanations. I have still a lot to learn in (La)TeX! Mar 12, 2021 at 18:59

Here is a solution using environ:

\usepackage{environ}
\NewEnviron{LiftBox}{\raisebox{.3em}{\BODY}}

\newtagform{myTag}{%
\fontsize{5}{0}\sffamily\selectfont\color{green}\begin{LiftBox}(}{)\end{LiftBox}}
\usetagform{myTag}


Complete example:

\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 :
$$\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}}$$
My favorite equation is \ref{fun_eq}, \eqref{fun_eq}, \cref{fun_eq}
\end{document}

• Great! There is some manual adjustment, but at least this solution is easy to understand! Thanks :-) Mar 12, 2021 at 17:27