5

In the following figure, the equations are well aligned in displayed mode but not in enumerated environment. I have done many permutations but I give up.

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}

\def\inner{%
\begin{multlined}[b][7cm]
\framebox[5cm]{Top LHS}\\
\framebox[5cm]{Middle LHS}\\
\framebox[5cm]{Bottom LHS}
\end{multlined}
    &= \begin{multlined}[t][7cm]
            \framebox[5cm]{Top RHS 1}\\
            \framebox[5cm]{Middle RHS 1}\\
            \framebox[5cm]{Bottom RHS 1}
        \end{multlined}\\
    &= \begin{multlined}[t][7cm]
            \framebox[5cm]{Top RHS 2}\\
            \framebox[5cm]{Middle RHS 2}\\
            \framebox[5cm]{Bottom RHS 2}
        \end{multlined}}

\begin{document}
\section*{displayed}
\begin{align*}
\inner
\end{align*}

\section*{enumerated}
\begin{enumerate}
    \item
    $\!
    \begin{aligned}[t]  
    \inner
    \end{aligned}
    $
\end{enumerate}
\end{document}

How to move a block of equations inside an enumeration down?

4
  • It is a good puzzle, isn't it? I don't find any information from mathmode.pdf about this pattern as well. Apr 17, 2013 at 14:59
  • It's the expected behaviour of [b] alignment, you would get the same if you went \item \begin{tabular}[b]..\end{tabular}..\begin{tabular}[t]..\end{tabular} (which is what you are doing, effectively. Apr 17, 2013 at 15:10
  • See also tex.stackexchange.com/q/95883/15925 Apr 17, 2013 at 18:43
  • @AndrewSwann: There is a difference on the LHS. Apr 17, 2013 at 19:06

3 Answers 3

7

if you change the

[...]
\def\inner{%
\begin{multlined}[b][7cm]
[...]

to

[...]
\def\inner{%
\begin{multlined}[t][7cm]
[...]

the first line will align nicely in the enumerate, and it doesn't seem to make any difference to the displayed version.

edit: okay, i lied (or actually, didn't pay enough attention to what was happening to the right hand side).

the following leaves the optional position of the first multlined as [t] (which lines up its first line with the enumerate's \item label. then it follows the first multlined by a line break, which needs to be adjusted (upward) to align properly. i think this is closer to what you had in mind.

\documentclass{article}

\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}

\def\inner{%
\begin{multlined}[t][7cm]
\framebox[5cm]{Top LHS}\\
\framebox[5cm]{Middle LHS\vphantom{p}}\\
\framebox[5cm]{Bottom LHS\vphantom{p}}
\end{multlined}\\[-1.3\baselineskip]  %%%  <-- here's the change
    &= \begin{multlined}[t][7cm]
            \framebox[5cm]{Top RHS 1}\\
                \framebox[5cm]{Middle RHS 1\vphantom{p}}\\
                \framebox[5cm]{Bottom RHS 1\vphantom{p}}
        \end{multlined}\\
    &= \begin{multlined}[t][7cm]
            \framebox[5cm]{Top RHS 2}\\
            \framebox[5cm]{Middle RHS 2\vphantom{p}}\\
            \framebox[5cm]{Bottom RHS 2\vphantom{p}}
        \end{multlined}}

\begin{document}
\section*{displayed}
\begin{align*}
\inner
\end{align*}

\section*{enumerated}
\begin{enumerate}
    \item
    $\!
    \begin{aligned}[t]  
    \inner
    \end{aligned}
    $
\end{enumerate}
\end{document}

while we're at it, let's make all the boxes the same depth (with \vphantom{p} since the "p" in the "Top" line has the descender that's making them uneven), and also even up the spacing around the equal signs. (i haven't checked, but i suspect there's a \, at the beginning of multlined -- there are some peculiar "initial" thin spaces in some of the amsmath multi-line structures, and it wouldn't surprise me if that was carried over into multlined.) since the visual space is tight on account of the boxes, i added the thin space at the end of the left-hand multlined because i think it looks nicer than removing space on the right of the equals sign.

output of example code

9
  • but the alignment for remaining output on the right hand side is not what I want. :-) Apr 17, 2013 at 14:46
  • +1 for making it look nice even if I think my way's better:-) Apr 17, 2013 at 14:51
  • @DavidCarlisle: The alignment on RHS does not conform to my requirement. Do you notice it? Please see this screenshot. Apr 17, 2013 at 14:53
  • @Bugbusters yes so you should use my answer then:-) Apr 17, 2013 at 14:59
  • @DavidCarlisle: I am waiting for another trick from her. Apr 17, 2013 at 15:01
5

I think you should use a display environment not inline math for a display

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}

\def\inner{%
\begin{multlined}[b][7cm]
\framebox[5cm]{Top LHS}\\
\framebox[5cm]{Middle LHS}\\
\framebox[5cm]{Bottom LHS}
\end{multlined}
    &= \begin{multlined}[t][7cm]
            \framebox[5cm]{Top RHS 1}\\
            \framebox[5cm]{Middle RHS 1}\\
            \framebox[5cm]{Bottom RHS 1}
        \end{multlined}\\
    &= \begin{multlined}[t][7cm]
            \framebox[5cm]{Top RHS 2}\\
            \framebox[5cm]{Middle RHS 2}\\
            \framebox[5cm]{Bottom RHS 2}
        \end{multlined}}

\begin{document}
\section*{displayed}
\begin{align*}
\inner
\end{align*}

\section*{enumerated}
\begin{enumerate}
    \item\mbox{}\par\vspace{\dimexpr-2\baselineskip-\abovedisplayskip\relax}
\begin{align*}
\inner
\end{align*}
\end{enumerate}
\end{document}

As the alignment point for the top part is b TeX doesn't really know where the first row of the inner box is, however if you assume that it is normal sized you can make a position that works reasonably well.

    \item\makebox[.5\linewidth]{ZZZZZZZZZZZZZZZZZZZ}\par
\vspace{\dimexpr-2\baselineskip-\abovedisplayskip\relax}
\begin{align*}

produces:

enter image description here

However if the top row is over-sized (as it is in the example because of the framebox) the alignment moves down to compensate so the baseline of the top row doesn't align with the item number, however this is (probably?) inevitable.

4
  • the alignment isn't very nice in the first line of the enumerated example. (a change of b to t in the original is all that's needed; see my answer.) Apr 17, 2013 at 14:43
  • @barbarabeeton I'd agree it looks better but I still think that putting an alignment in $..$ has to be wrong on principle. I probably have the negative spacing wrong I'd have to look what space actually is needed (rather than baselineskip and abovedisplayskip) to get the baselines more aligned clearly by adjusting that space anything could be aligned. Apr 17, 2013 at 14:50
  • i'm not disagreeing about putting an alignment in $...$. but it's not the first time this has been asked for, and having multiple "items" of this sort strung out one after the other gets very spacy and ugly. they really look better closed up. (probably using a subequations approach would be better though, as well as more logical.) Apr 17, 2013 at 18:23
  • Please kindly see my solution above. Apr 18, 2013 at 20:11
2

Mission accomplished!

enter image description here

\documentclass{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}

\begin{document}

\begin{enumerate}
\item
$\!
\begin{aligned}[t]  
\mathrlap{\framebox[5cm]{Top LHS}}\rule{7cm}{0pt}\\
\rule{3.5cm}{0pt}\mathclap{\framebox[5cm]{Middle LHS}}\rule{3.5cm}{0pt}\\
\rule{7cm}{0pt}\mathllap{\framebox[5cm]{Bottom LHS}}
    &= \begin{multlined}[t][7cm]
            \framebox[5cm]{Top RHS 1}\\
            \framebox[5cm]{Middle RHS 1}\\
            \framebox[5cm]{Bottom RHS 1}
        \end{multlined}\\
    &= \begin{multlined}[t][7cm]
            \framebox[5cm]{Top RHS 2}\\
            \framebox[5cm]{Middle RHS 2}\\
            \framebox[5cm]{Bottom RHS 2}
        \end{multlined}
\end{aligned}
$
\end{enumerate}
\end{document}

Edit:

With better user interfaces.

\documentclass[twocolumn]{article}
\usepackage[a4paper,margin=1cm]{geometry}
\usepackage{mathtools}
\newlength\EWD
\newlength\HWD
\newlength\HHWD

\def\Init{%
    \settowidth{\EWD}{${}={}$}%
    \setlength{\HWD}{0.5\dimexpr\linewidth-\EWD\relax}%
    \setlength{\HHWD}{0.5\HWD}}

\def\TopLHS#1{\mathrlap{#1}\rule{\HWD}{0pt}}
\def\MiddleLHS#1{\rule{\HHWD}{0pt}\mathclap{#1}\rule{\HHWD}{0pt}}
\def\BottomLHS#1{\rule{\HWD}{0pt}\mathllap{#1}}

\begin{document}

\begin{enumerate}
\item\Init
$\!
\begin{aligned}[t]  
\TopLHS{\framebox[3cm]{Top LHS}}\\
\MiddleLHS{\framebox[3cm]{Middle LHS}}\\
\BottomLHS{\framebox[3cm]{Bottom LHS}}
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 1}\\
            \framebox[3cm]{Middle RHS 1}\\
            \framebox[3cm]{Bottom RHS 1}
        \end{multlined}\\
    &= \begin{multlined}[t][\HWD]
            \framebox[3cm]{Top RHS 2}\\
            \framebox[3cm]{Middle RHS 2}\\
            \framebox[3cm]{Bottom RHS 2}
        \end{multlined}
\end{aligned}
$
\end{enumerate}
\end{document}

Note: I don't know the best place at which I should invoke the \Init. If you have any suggestion, please kindly let me know.

1
  • 1
    yes +1 putting a rule at the top of a box to fake a second alignment point is a standard trick, I still claim that putting an alignment in text math is the wrong thing to do, but since in this case it's hard to make the right markup do the right thing I won't complain too much:-) Apr 18, 2013 at 20:21

You must log in to answer this question.

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