9

When the name is long, the centering of the equations is off even though the tagged name wouldn't overlap the content. How can I center equations with a long name?

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
  1 &= 1\\
  2 &= 2\tag{This is a long tag}\\
  3 &= 3
\end{align*}
\end{document}

From the image below, we can see that there is enough space to center the equations with the document and not have overlap.

enter image description here

6
  • Is inserting \mkern-50mu or \mspace{-50mu} after the second equation an option? You can automate it but is it an option to modify the equation set instead of tag handling?
    – percusse
    Aug 5, 2013 at 13:24
  • @percusse \mkern-50mu moves it over but is that guess on how far to move it or is would 50 mu units be the actual amount to center?
    – dustin
    Aug 5, 2013 at 13:36
  • Just a quick guess. mu is math unit and 1/18 of 1em. Hence the round number.
    – percusse
    Aug 5, 2013 at 13:44
  • @percusse do you know if there is a command that will figure out the correct adjustment to center?
    – dustin
    Aug 5, 2013 at 13:47
  • 1
    You can measure the length of your tag and insert the required negative math space. However, amsmath parses the content twice first measures the content then typesets so it might be tricky. Use mathtools anyway :)
    – percusse
    Aug 5, 2013 at 13:49

2 Answers 2

7

One option is to hide the tag width using, for example, a \makebox; inside the Dequation environment, the tag width will not be taken into account:

\documentclass{article}
\usepackage{amsmath}

\makeatletter
\newenvironment{Dequation}
  {%
  \def\tagform@##1{%
    \maketag@@@{\makebox[0pt][r]{(\ignorespaces##1\unskip\@@italiccorr)}}}%
  \ignorespaces
  }
  {%
  \def\tagform@##1{\maketag@@@{(\ignorespaces##1\unskip\@@italiccorr)}}%
  \ignorespacesafterend
  }
\makeatother    

\begin{document}

A regular \texttt{align*} with long tags:
\begin{align*}
  1 &= 1\\
  2 &= 2\tag{This is a long tag}\\
  3 &= 3\tag{This is an even longer tag}
\end{align*}
A regular \texttt{align*} without tags, for comparison:
\begin{align*}
  1 &= 1\\
  2 &= 2\\
  3 &= 3
\end{align*}
An \texttt{align*} with long tags inside \texttt{Dequation}:
\begin{Dequation}
\begin{align*}
  1 &= 1\\
  2 &= 2\tag{This is a long tag}\\
  3 &= 3\tag{This is an even longer tag}
\end{align*}
\end{Dequation}
The initial regular \texttt{align*} with long tags, for comparison:
\begin{align*}
  1 &= 1\\
  2 &= 2\tag{This is a long tag}\\
  3 &= 3\tag{This is an even longer tag}
\end{align*}

\end{document}

enter image description here

5

You could add the longest tag on the opposite side as a \phantom in order to "restore" the horizontal shift:

enter image description here

\documentclass{article}
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\begin{document}
\begin{align*}
  1 &= 1 \\
  2 &= 2 \\
  3 &= 3
\end{align*}
\begin{align*}
  1 &= 1 \\
  2 &= 2 \tag{This is a long tag} \\
  3 &= 3
\end{align*}
\begin{align*}
  1 &= 1 \\
  \phantom{\text{(This is a long tag)}}2 &= 2 \tag{This is a long tag} \\
  3 &= 3
\end{align*}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .