# What is a good way to stack things in an equation?

I have a string of inequalities, and somewhere in the middle I have two things which are equal. To fit this nicely on a single line, I would like to stack the equal things. So I wanted to do something like this (using the stackrel package):

$A \leq \stackrel[B]{C}{\parallel} \leq D$

However this makes B and C smaller. I can fix this with an even kludgier hack:

$A \leq \stackrel[\text{\normalsize B}]{\text{\normalsize C}}{\parallel} \leq D$

My question is: What the right way to do something like this?

Edit: I would like something without a begin and end if possible.

• You could hide the environment from a solution below in a macro: \newcommand{\eqnpair}{\begin{array}{c} #1 \\ #2 \end{array}} – Neil Olver Aug 9 '10 at 22:27
• Incidentally, I'd use \textstyle B instead of \text{\normalsize $B$}. – Loop Space Aug 10 '10 at 8:41
• I think this may be related to this question perhaps tex.stackexchange.com/questions/177212/vertical-equality-in in what you want to do, as far as solution goes, yes? – Guido Jorg Jul 14 '14 at 13:09

## 4 Answers

I am going to avoid the topic of whether or not it is a good idea to do something like this and answer your specific question. Your problem is that \stackrel implicitly takes the B and C out of displaystyle. To fix this, you just need to explicitly tell it to typeset them in displaystyle:

$A \leq \stackrel[\displaystyle B]C}{\parallel} \leq D$

• \stackrel is for placing superscripts, so it's not the right one,

• \substack is also intended for subscripts or superscripts, so it's not the best choice,

• \genfrac would be an option: $A \leq \genfrac{}{}{0pt}{0}{B}{C} \leq D.$, but there might be more space between the letters than you might wish,

• the aligned environment would be possible,

• an array environment seems natural: $A \leq \begin{array}{c} B \\ C \end{array}\leq D.$

• if you use array you could modify \arraystretch locally t get it more cramped, another quick way is to use the optional argument of \ like in $A \leq \begin{array}{c} B \\[-3pt] C \end{array}\leq D$

Better use $...$ instead of $$...$$.

Having looked at the output of the various possibilities, I can't help feeling that this question should carry the "don't do that" tag! I find myself wondering exactly what the circumstances are that lead you to want to do this. My guess is that the overall expression is quite long with lots of terms and so putting them line-by-line makes it just too big. So the aim is to make the full expression compact. Given that it (presumably) doesn't quite fit on one line, using the equalities as compression points does make a certain amount of sense. But how about using just a little more space to make it just a little clearer?

So with that in mind, here's my offering (using the amsmath package):

\begin{align*}
A \le B \le C &\le D \\
&\phantom{{}\le{}}\parallel \\
&\phantom{{}\le{}}E \le F \le G \le H
\end{align*}


Note the \phantoms. Putting the alignment tag after the \le on the first line leads to bad spacing between the \le and the D, so we have to shift the vertical equals sign and the E along a bit so that they correctly lie under the D. Without the extra braces, the space either side of the \le gets trimmed in the \phantom making it too short.

For your particular case, I'd write it

A \leq B = C \leq D


But in general, if you want to stack things, I suppose it could be done with an AMS matrix environment,

A \leq \begin{matrix}B \\ \parallel \\ C\end{matrix} \leq D


although there's probably something perfectly appropriate for this task.

(By the way, I'm not too happy with using \parallel to get a rotated equals sign, but if you're not willing to just use a regular unrotated equals sign, I don't know the proper way to do it.)

• A, B, C, and D are placeholders for longer terms. It just barely fits on one line. The point of this equation was to show that B sits between A and D. The equality to C is to remind the reader what B is. – Richard Dore Aug 15 '10 at 5:38
• @RichardDore Then, "$A\leq B\leq D$. Recall that $B=C$." – David Richerby Jun 16 '16 at 8:23