# Aligning equations with gather with long equation tags in a minipage

I would like to put two equations under each other, center aligned with gather. To complicate the matter, I would need two columns of such equations, thus I enclosed them in a minipage. This is prone to some problems... The equations do not quite get aligned:

\documentclass[a4paper]{article}

% Make the equation fit on the page.
\usepackage[margin=2.5cm]{geometry}

\usepackage{amsmath}

\newcommand*{\subtype}{\mathrel{<:}}
\newcommand*{\subtypeDep}{\mathrel{<:_{\textrm{dep}}}}
\newcommand*{\subtypePt}{\mathrel{<:_{\textrm{pt}}}}
\newcommand*{\lit}{\texttt}

\begin{document}

\begin{minipage}[t]{0.5\linewidth}
\begin{gather}
\tau \subtype \tau \text, \tag{\textsc{S-Refl}} \\
\frac{
\delta_1 \subtypeDep \delta_2 \quad \rho_1 \subtypePt \rho_2
}{
\delta_1\,\rho_1 \subtype \delta_2\,\rho_2
} \text, \tag{\textsc{S-Var}}
\end{gather}
\end{minipage}%
\begin{minipage}[t]{0.5\linewidth}
\begin{align}
\delta &\subtypeDep \delta \text, \tag{\textsc{SD-Refl}} \\
\lit{const} &\subtypeDep \lit{marking} \text, \tag{\textsc{SD-Marking}} \\
\rho &\subtypePt \rho \text, \tag{\textsc{SPt-Relf}} \\
\lit{int} &\subtypePt \lit{double} \tag{\textsc{SPt-Double}}
\end{align}
\end{minipage}

\end{document}


Is there any possible workaround for the deficiencies of varwidth?

• I can't reproduce your problem. both equation are centered. To see, what is going wrong at you, please provide complete small document -- MWE -- which will show your problem. – Zarko Apr 12 '17 at 11:04
• Sorry, I thought I managed to isolate the problem properly. Truth is, this looks quite like a duplicate of tex.stackexchange.com/questions/360447/… now (with the twist the the suggested workaround to use gathered is not really applicable in my case, I think). – Kristóf Marussy Apr 12 '17 at 11:17
• width of minipage is to small for properly working of gather. If you increase it to 0.6\textwidth, you will obtain desired result. – Zarko Apr 12 '17 at 11:25
• At least judging by my eyes, there seems to be sufficient space to lay out the equations properly. Is there some length or other parameter I could change for that effect? – Kristóf Marussy Apr 12 '17 at 11:34

The top equation in the left box is centered in the allotted space; the bottom one, however, is too wide and would clash with the tag, so it's moved left.

You can use eqparbox for this, making the top equation as wide as the bottom one.

The first argument to \matheqmakebox is an arbitrary (but unique) tag.

\documentclass[a4paper]{article}

% Make the equation fit on the page.
\usepackage[margin=2.5cm]{geometry}

\usepackage{amsmath}
\usepackage{eqparbox}

\usepackage{lipsum}

\newcommand*{\subtype}{\mathrel{<:}}
\newcommand*{\subtypeDep}{\mathrel{<:_{\textrm{dep}}}}
\newcommand*{\subtypePt}{\mathrel{<:_{\textrm{pt}}}}
\newcommand*{\lit}{\texttt}

\newcommand{\matheqmakebox}[2]{%
\eqmakebox[#1]{$\displaystyle{#2}$}%
}

\begin{document}

\fboxrule=0.1pt
\fboxsep=-\fboxrule

\lipsum*[2]
\begin{center}
\setlength{\abovedisplayskip}{0pt}
\fbox{\begin{minipage}[t]{0.5\linewidth}
\begin{gather}
\matheqmakebox{A}{
\tau \subtype \tau,
}
\tag{\textsc{S-Refl}} \\
\matheqmakebox{A}{
\frac{
\delta_1 \subtypeDep \delta_2 \quad \rho_1 \subtypePt \rho_2
}{
\delta_1\,\rho_1 \subtype \delta_2\,\rho_2
},}
\tag{\textsc{S-Var}}
\end{gather}
\end{minipage}}%
\fbox{\begin{minipage}[t]{0.5\linewidth}
\begin{align}
\delta &\subtypeDep \delta \text, \tag{\textsc{SD-Refl}} \\
\lit{const} &\subtypeDep \lit{marking} \text, \tag{\textsc{SD-Marking}} \\
\rho &\subtypePt \rho \text, \tag{\textsc{SPt-Relf}} \\
\lit{int} &\subtypePt \lit{double} \tag{\textsc{SPt-Double}}
\end{align}
\end{minipage}}
\end{center}
\lipsum[3]

\end{document}


I used \fbox just to show the box boundaries.

Just for completeness, here is another example without boxes.

\documentclass[twocolumn]{article}
\usepackage{amsmath}
\usepackage{lipsum}

\begin{document}

\lipsum*[2]
\begin{gather}
short \tag{widetag} \\
lllllloooooonnnggg\tag{widetag}
\end{gather}
\lipsum[3]

\end{document}