2

Using minipage to have side-by-side equations seems to give them an offset when one of them contains a fraction:

Blockquote

Code here:

\vspace{0.5cm}
\begin{minipage}{.5\linewidth}
    \begin{equation}
    \alpha (u,v) = \frac{N\!A}{n_s \sqrt{1 - \left(\frac{N\!A \rho}{n_s}\right)^2}}
    \label{eq:alpha}
    \end{equation}
\end{minipage}
\begin{minipage}{.5\linewidth}
    \begin{equation}
    d = \alpha \rho z
    \label{eq:disparity}
    \end{equation}
\end{minipage}
\vspace{0.5cm}

Any idea how to fix this? or a better way to achieve the same results sans offset?

1
  • Welcome to TeX SX! minipages are vertically centred by default. Try \begin{minipage}[t]
    – Bernard
    Jun 18, 2020 at 17:13

3 Answers 3

1

You need to ensure that the two objects have the same height (and depth). The simplest is to typeset each equation twice, one for output and one as a vertical phantom.

In the phantom I disable \label, so it won't be seen.

The optional argument is the fraction of space to reserve for the left equation.

\documentclass{article}
\usepackage{amsmath}
\usepackage{lipsum} % just for the example

\newcommand{\sidebysideequations}[3][0.5]{%
  \begin{equation*}
  \begin{minipage}{#1\displaywidth}%
  \begin{equation}\vphantom{\def\label##1{}#3}#2\end{equation}
  \end{minipage}
  \begin{minipage}{\dimexpr\displaywidth-#1\displaywidth}
  \begin{equation}\vphantom{\def\label##1{}#2}#3\end{equation}
  \end{minipage}
  \end{equation*}
}

\begin{document}

References: \eqref{eq:alpha}, \eqref{eq:disparity}

\lipsum[1][1-5]
\sidebysideequations[0.6]{
    \alpha (u,v) = \frac{N\!A}{n_s \sqrt{1 - \left(\frac{N\!A \rho}{n_s}\right)^2}}
    \label{eq:alpha}
}{
    d = \alpha \rho z
    \label{eq:disparity}
}
\lipsum[2][1-5]

\end{document}

enter image description here

2
  • That works, thanks! Only issue is that the left-hand equation seems to have an extra indent - it's positioned further right than when using 'vanilla' minipage
    – ajsc4
    Jun 20, 2020 at 8:57
  • @ajsc4 Optical illusion due to the minipage on the left being wider than the one on the right.
    – egreg
    Jun 20, 2020 at 11:34
4

Posted for Barbara who is having computer issues.

@Bernard has provided the canonical reason for the misalignment: minipages are vertically centered by default. But the suggestion for correcting the alignment, using the option [t], doesn't have the desired effect; the second equation is now just a bit higher than the first.

@egreg has produced the desired result, along with a differently formulated reason for the misalignment. But there is a more compact way to get this result as long as you understand the reason for the misalignment and the way that (La)TeX measures the height and depth of a math expression. The \vphantom need contain just the elements of the "taller" expression; it's not necessary to set the whole thing twice. And if one of the equations is taller on the top and the other one deeper on the bottom, a minimal \vphantom can be applied as necessary to each, to even out the height and depth. (That is left as an exercise to the reader.)

\documentclass{article}

\begin{document}
\thispagestyle{empty}
Using a \verb+\vphantom+:

\noindent
\begin{minipage}{.5\linewidth}
    \begin{equation}
    \alpha (u,v)
       = \frac{N\!A}{n_s \sqrt{1 - \left(\frac{N\!A \rho}{n_s}\right)^2}}
    \label{eq:alpha}
    \end{equation}
\end{minipage}%
\begin{minipage}{.5\linewidth}
    \begin{equation}
    d = \alpha \rho z
       \vphantom{\frac{N}{\sqrt{\left(\frac{N}{n_s}^2\right)}}}
    \label{eq:disparity}
    \end{equation}
\end{minipage}

\bigskip

using the optional \verb+[t]+ for top alignment:

\noindent
\begin{minipage}[t]{.5\linewidth}
    \begin{equation}
    \alpha (u,v)
       = \frac{N\!A}{n_s \sqrt{1 - \left(\frac{N\!A \rho}{n_s}\right)^2}}
    \end{equation}
\end{minipage}%
\begin{minipage}[t]{.5\linewidth}
    \begin{equation}
    d = \alpha \rho z
    \end{equation}
\end{minipage}

\end{document}

enter image description here

2
  • Thanks! Where does \verb come into it? Not sure if I'm missing something - egreg's method works for me while yours doesn't seem to.
    – ajsc4
    Jun 20, 2020 at 8:54
  • @ajsc4 Barbara just used verb in the documentation to make [t] it isn't used in the code Jun 20, 2020 at 9:03
1

We need to set common baseline of two outputs of display math. This can be done by \unskip\unpenalty in \vbox just after the display math is closed and paragraph is finished:

\def\twodisplays#1#2{\vbox{\hsize=.5\hsize$$#1$$\par\unskip\unpenalty}%
                     \vbox{\hsize=.5\hsize$$#2$$\par\unskip\unpenalty}}

Test:
$$\twodisplays
  {
    \alpha (u,v) = {N\!A \over n_s \sqrt{1 - \left( N\!A \rho \over n_s\right)^2}}
    \eqno (1)
  }
  {
    d = \alpha \rho z
    \eqno (2)    
  }
$$
next text.

You must log in to answer this question.

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