# Is there a way to have two or more equations on one line, each separately numbered and equal signs vertically aligned?

I will start with examples in order to more easily explain what I'm after. The first example shows how I would like four equations arranged. The vertical alignment of the equal signs in each row is perfect, of course, because each is a single line in an align structure. But, not all four equations can be numbered. The other down side is lack of control of the horizontal spread without using a parbox.

The second example shows how I would like them numbered, but sacrifices the vertical alignment of the equal signs in each row, because they each have different vertical heights.

The third example is almost perfect. By swapping two of the equations and aligning the parboxes by [b], in this arrangement, the heights match better, but up close you can see the second row is very slightly off. It's not bad and it's the current solution I'm using.

In the second and third examples, the horizontal spread is exactly how I want it, being controlled by the parbox widths.

Here's the code:

\documentclass[10pt,a5paper]{book}

\usepackage[paperheight=9.5cm,paperwidth=13cm, margin=6mm]{geometry}

\usepackage{amsmath}
\usepackage{mathtools}

\newcommand{\pd}{\partial}
\newcommand{\gep}{\epsilon}
\newcommand{\gm}{\mu}
\newcommand{\gr}{\rho}

\thispagestyle{empty}

\begin{document}

Example 1
\begin{subequations}
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t} & = 0 &
\vec{\nabla}\cdot\vec{B} & = 0 \label{eqn:hB} \\
\vec{\nabla}\cdot\vec{E} &= \frac{\gr}{\gep_0} &
\vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
&= \gm_0 \vec{j}\label{eqn:ihB}
\end{align}
\end{subequations}

Example 2

\begin{subequations}
\parbox[c]{\textwidth*7/16}{
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t} & = 0 \\
\vec{\nabla}\cdot\vec{B} & = 0 \label{eqn:hB}
\end{align}}
\parbox[c]{\textwidth*7/16}{
\begin{align}
\vec{\nabla}\cdot\vec{E} &= \frac{\gr}{\gep_0} \\
\vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
&= \gm_0 \vec{j}\label{eqn:ihB}
\end{align}}
\end{subequations}

Example 3

\begin{subequations}
\parbox[b]{\textwidth*7/16}{
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t} & = 0 \\
\vec{\nabla}\cdot\vec{E} &= \frac{\gr}{\gep_0}
\end{align}}
\parbox[b]{\textwidth*7/16}{
\begin{align}
\vec{\nabla}\cdot\vec{B} & = 0 \label{eqn:hB} \\
\vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
&= \gm_0 \vec{j}\label{eqn:ihB}
\end{align}}
\end{subequations}

\end{document}


The AMS align stuff does horizontal alignment of multiple equations above each other in a column well, it also does vertical alignment of multiple equations beside each other in a row, but how does one get multiple equation numbers on one line?

Is there a solution that gives full control of all three aspects simultaneously: multiple equation numbers on one line, horizontal alignment and vertical alignment?

As there is more than one answer already, I'm adding some notes here, so as not to have to repeat myself in comments.

I will use phantoms and other structural tweaks when nothing else will do and that happens more than occasionally, unfortunately. If the answer to my question is that tweaks are the only solution, then so be it. But it seems to me that creating an align structure that allows having more than one equation number horizontally would solve all of this with zero tweaks. Is anyone from AMS development listening?

I appreciate all the suggestions below, because in lieu of having a built in solution, tweaks is all I have left and it's good to see how others solve this stuff.

An extra note on the semantics of vertical and horizontal alignment: I have at least two software programs that use these alignment terms to refer to the direction in which you move the elements to obtain alignment. Hence, vertical alignment takes elements in a row and moves them up or down to line them up and horizontal alignment takes elements in a column and moves them left or right to line them up. It also makes sense to me that the basic direction of the elements themselves could be used to define these terms, that is, above each other in a vertical line and beside each other in a horizontal line, giving the opposite definition to the above. The former definition refers to the method, the latter refers to the result.

• Off-topic: I would replace \vec{j} with \vec{\jmath}. In fine math typography, it's common to suppress the "dot" of the letters i and j if the letters are also topped by "accent characters" such as hats, tildes, and arrows.
– Mico
Sep 6 '18 at 5:43
• It seems that exemple 2 does not sacrifies the vertical but the /horizontal/ alignmenti ?
– Jhor
Sep 6 '18 at 6:56
• @Mico I'm a coauthor/editor on this project and this is a block of code that I have started to fix the overall structure of and haven't got to the fine detail yet. You make a good point that I am already aware of. Sep 6 '18 at 15:12
• @Jhor Vertical alignment is when you move elements in a horizontal line up and down to align them. None of these examples has a problem with horizontal alignment. The equal signs in the first row of example 2 are not aligned vertically. They do not need to be juggled from side to side (which is horizontal alignment), they need to be juggled up and down (which is vertical alignment). Sep 6 '18 at 15:19

Here is another idea. The alignment can be obtained very easily. Depending on how you refer to the equations, there might/should/will be a way to refer to them. I have not even started looking at the question how to refer to the equations since I fear you may reject this proposal right away, which is of course perfectly OK.

\documentclass[10pt,a5paper]{book}
\usepackage[paperheight=9.5cm,paperwidth=13cm, margin=6mm]{geometry}

\usepackage{amsmath}
\usepackage{mathtools}
\newcommand{\pd}{\partial}
\newcommand{\gep}{\epsilon}
\newcommand{\gm}{\mu}
\newcommand{\gr}{\rho}

\thispagestyle{empty}

\begin{document}

\begin{subequations}
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t} & = 0
&& (\stepcounter{equation}\hypertarget{eq:Hom1}{\text{\theequation}})
& \vec{\nabla}\cdot\vec{E} &= \frac{\gr}{\gep_0} \label{eq:MW1a}\\
\vec{\nabla}\cdot\vec{B}& = 0
&& (\stepcounter{equation}\hypertarget{eq:Hom2}{\text{\theequation}})
&  \vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
&= \gm_0 \vec{j}\label{eq:MW2}
\end{align}
\end{subequations}

The so--called "homogeneous"' Maxwell equations are just a Bianchi identity.

\begin{subequations}
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t} & = 0
&& (\stepcounter{equation}\text{\theequation}\stepcounter{equation})
& \vec{\nabla}\cdot\vec{E} &= \frac{\gr}{\gep_0} \label{eq:MW3}\\
\vec{\nabla}\cdot\vec{B}& = 0
&  \vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
&= \gm_0 \vec{j} \label{eq:MW4}
\end{align}
\end{subequations}

\end{document} OLDER STUFF: The vertical alignment of your second example can be fixed by adding a single few \vphantoms.

\documentclass[10pt,a5paper]{book}
\usepackage{tikzpagenodes} % just for illustration
\usepackage[paperheight=9.5cm,paperwidth=13cm, margin=6mm]{geometry}

\usepackage{amsmath}
\usepackage{mathtools}

\newcommand{\pd}{\partial}
\newcommand{\gep}{\epsilon}
\newcommand{\gm}{\mu}
\newcommand{\gr}{\rho}

\thispagestyle{empty}

\begin{document}

Based on example 2

\begin{subequations}
\parbox[c]{\textwidth*7/16}{
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t}\vphantom{\frac{\pd \vec{E}}{\pd t}} & = 0 \\
\vec{\nabla}\cdot\vec{B}\vphantom{\frac{\pd \vec{E}}{\pd t}} & = 0 \label{eqn:hB}
\end{align}}
\parbox[c]{\textwidth*8/16}{
\begin{align}
\vec{\nabla}\cdot\vec{E}\vphantom{\frac{\pd \vec{E}}{\pd t}} &= \frac{\gr}{\gep_0} \\
\vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
\vphantom{\frac{\pd \vec{E}}{\pd t}}&= \gm_0 \vec{j}\label{eqn:ihB}
\end{align}}
\end{subequations}
\tikz[remember picture,overlay] {%
\foreach \X in {1.3,2.4}
{    \draw [red,opacity=0.5]
([yshift=-\X*1cm]current page text area.north west) --
([yshift=-\X*1cm]current page text area.north east);}
}

\end{document} ADDENDUM: DISCLAIMER: No, I do not understand Heiko's magical code at all, and yes, I know that the equation numbers are too large. The only point of this addendum is just to report a curious observation: if one wraps your equations in Heiko Oberdiek's code, they align almost perfectly. This happens already without any further ado. IMHO this suggests that there should be a rather basic solution that does not rely on "sledge hammer" packages (using Bernard's terminology ;-).

\documentclass{article}
\usepackage{mathtools}
\usepackage{tikzpagenodes} % just for illustration

\makeatletter % from https://tex.stackexchange.com/a/387283/121799
\newif\ifEvenSpacing@Uneven
\newcommand*{\EvenSpacing}{%
\par
\begingroup
\EvenSpacing@Try{#1}%
\@whilesw\ifEvenSpacing@Uneven\fi{%
\EvenSpacing@Try{#1}%
}%
#1\par
\endgroup
}
\newcommand*{\EvenSpacing@Try}{%
\lineskip=0pt
\normallineskip=0pt
\settototalheight{\dimen0}{\parbox{\linewidth}{#1}}%
\lineskip=1pt
\normallineskip=1pt
\settototalheight{\dimen2}{\parbox{\linewidth}{#1}}%
\ifdim\dimen0=\dimen2
\EvenSpacing@Unevenfalse
\else
\EvenSpacing@Uneventrue
\fi
}
\makeatother
\newcommand{\pd}{\partial}
\newcommand{\gep}{\epsilon}
\newcommand{\gm}{\mu}
\newcommand{\gr}{\rho}

\begin{document}

\section*{Without Heiko's magic}

\begin{subequations}
\parbox[c]{\textwidth*7/16}{
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t} & = 0 \\
\vec{\nabla}\cdot\vec{B} & = 0 \label{eqn:hB}
\end{align}}
\parbox[c]{\textwidth*8/16}{
\begin{align}
\vec{\nabla}\cdot\vec{E} &= \frac{\gr}{\gep_0} \\
\vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
&= \gm_0 \vec{j}\label{eqn:ihB}
\end{align}}
\end{subequations}

\section*{With Heiko's magic}

\EvenSpacing{\begin{subequations}
\parbox[c]{\textwidth*7/16}{
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t} & = 0 \\
\vec{\nabla}\cdot\vec{B} & = 0 \label{eqn:hB'}
\end{align}}
\parbox[c]{\textwidth*8/16}{
\begin{align}
\vec{\nabla}\cdot\vec{E} &= \frac{\gr}{\gep_0} \\
\vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
&= \gm_0 \vec{j}\label{eqn:ihB'}
\end{align}}
\end{subequations}}

\tikz[remember picture,overlay] {%
\foreach \X in {1.82,2.55,5.8,6.8}
{    \draw [red,opacity=0.5]
([yshift=-\X*1cm]current page text area.north west) --
([yshift=-\X*1cm]current page text area.north east);}
}

\end{document} • Yes, the good old phantoms. See my notes in the addendum to the OP. Sep 6 '18 at 23:49
• @GeoffPointer I agree with you that it would be nice to have such an environment. However, I am not a maintainer of AMS (unless you refer to the Aspen Marmot Society ;-) so I can't help you. On the other hand, what are you doing if you have some \left( ... \right) brackets that run over more than one line? Do you have anything that is strictly better than the good old \vphantoms. Note also that daleif is often on the chat, you may try to contact him directly.
– user121799
Sep 7 '18 at 0:04
• @GeoffPointer And I guess someone might be able to cook up some solution based on this post. But I am certainly not the someone, especially after having read what this is good for.
– user121799
Sep 7 '18 at 0:12
• I agree there will always be situations where tweaking is necessary. You can't program for every eventuality. In my case here, I would still need a parbox to get the right spread to my eyes on the page, but I just thought that multiple equation numbers on one line is a fundamental enough structure to be worthy of a software level solution. I'll have a go at trying to make an impression where it might count. Sep 7 '18 at 0:18
• If you put those red lines on your vphantom solution the first row is obviously still not aligned and the second is fractionally off. Using [b] alignment on the parboxes works much better. I will continue to mess around with this method to see what I can do. I'm staying away from the Heiko thing for now. Sep 7 '18 at 2:21

I propose this solution, based on tabularx. Note how each of the align environments in cells has to be inserted in a group. I added barious small improvements, with the esdiff (for easy typing of partial derivatives) and esvect (for nicer vector arrows) packages.

\documentclass[10pt, a5paper]{book}

\usepackage[paperheight=9.5cm,paperwidth=13cm, margin=6mm]{geometry}

\usepackage{mathtools}
\usepackage[b]{esvect}
\usepackage{esdiff}
\usepackage{tabularx}
\newcommand{\pd}{\partial}
\newcommand{\gep}{\epsilon}
\newcommand{\gm}{\mu}
\newcommand{\gr}{\rho}

\makeatletter
\newcommand*{\compress}{\@minipagetrue}
\thispagestyle{empty}

\begin{document}

Example

\begin{subequations}
{\begin{align}
\vv{\nabla}\times \vv{E} +\smash[t]{\diffp{\vv{B}}{t}} & = 0 \\[2pt]
\vv{\nabla}\cdot\vv{E} &= \frac{\gr}{\gep_0}
\end{align}}
&
{\begin{align}
\vv{\nabla}\cdot\vv{B} & = 0 \label{eqn:hB}%
\\%
\vv{\nabla}\times \vv{B} - \gm_0 \gep_0 \diffp{\vv{E}}{t}
&= \gm_0 \vv{j}\label{eqn:ihB}
\end{align}}
\end{tabularx}
\end{subequations}

\end{document} • A bit of a weighty solution, but one that I will investigate . See the addendum in the OP. Sep 6 '18 at 23:48
• What I like about this is the result has the equal signs perfectly aligned on both lines. Sep 7 '18 at 2:18

This answer is on the topic of how to work out the minimal and best vphantom solution. From the OP, I will focus on Example 3, as this is the order of the equation numbers I want in the book.

The point may seem at first that the first row entries have to be the same size, but the key is that they must have the same alignment as well as taking up the same amount of space overall. Yes, the field derivatives are taller than the rho on epsilon zero, but notice that the align lines up the fraction line with the middle of the equals sign and that relative to this, the subscripted epsilon takes up more vertical space below it than the del t.

The first row is easy because the right hand equation is shallower than the left hand one, both above and below the equals sign. So here the entire fraction is necessary in the vphantom and no correction is necessary on the left.

In the second row, the epsilon zero on the left is deeper than the del t on the right, but the del vec E on the right is higher than the rho on the left. To emphasise my point, you can see that I have deleted what's irrelevant from the fractions in the vphantoms that I have used here.

\documentclass[10pt,a5paper]{book}

\usepackage[paperheight=4.7cm,paperwidth=13cm, margin=6mm]{geometry}

\usepackage{amsmath}
\usepackage{mathtools}

\newcommand{\pd}{\partial}
\newcommand{\gep}{\epsilon}
\newcommand{\gm}{\mu}
\newcommand{\gr}{\rho}

\thispagestyle{empty}

\begin{document}

Example 4

\begin{subequations}

\parbox[b]{\textwidth*13/32}{
\begin{align}
\vec{\nabla}\times \vec{E} +\frac{\pd \vec{B}}{\pd t} & = 0 \\
\vec{\nabla}\cdot\vec{E} \vphantom{\frac{\pd \vec{B}}{\pd t}} &= \frac{\gr}{\gep_0}
\end{align}}
\parbox[b]{\textwidth*17/32}{
\begin{align}
\vec{\nabla}\cdot\vec{B} \vphantom{\frac{\pd \vec{B}}{}} & = 0 \label{eqn:hB} \\
\vec{\nabla}\times \vec{B} - \gm_0 \gep_0 \frac{\pd \vec{E}}{\pd t}
\vphantom{\frac{}{\gep_0}} &= \gm_0 \vec{j}\label{eqn:ihB}
\end{align}}\newline
\end{subequations}

\end{document}
`

The result, with perfect alignment: 