3

I could find several questions regarding systems of equations but couldn't find any that matched my case.

I'd like stack systems of equations on top of each other aligned at their equals signs. These systems themselves are aligned at their + and - signs and I don't want to mess their alignment in the stacking process. Below is an illustration of what I want.

Desired result

Parts that should be aligned are enclosed in the rectangles but the rectangles don't need and generally shouldn't be aligned with each other.

This was achieved with a code:

\documentclass{standalone}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage{booktabs}

\DeclareUnicodeCharacter{22C5}{\cdot{}}

\begin{document}
$\begin{array}{r @{\;} c @{\;} l}
\multirow{3}{*}{$\left\lbrace\begin{array}{@{} r @{\;} c @{\;} r @{\;} c @{\;} r @{}}
a⋅(-1)^2 &+& b⋅(-1) &+& c \\
a⋅0^2    &+& b⋅0    &+& c \\
a⋅2^2    &+& b⋅2    &+& c \\
\end{array}\right.$}
    &=& 12 \\
    &=& 5  \\
    &=& -3 \\
\\
\multirow{2}{*}{$\left\lbrace\begin{array}{@{} r @{\;} c @{\;} r @{}}
 a &-& b  \\
4a &+& 2b \\
\end{array}\right.$}
    &=& 7              \\
    &=& -8 \qquad ||:2 \\
\\
\multirow{2}{*}{$\begin{array}{r} \\ + \\ \end{array}\left\lbrace\begin{array}{@{} r @{\;} c @{\;} r @{}}
a  &-& b \\
2a &+& b \\
\end{array}\right.$}
    &=& 7  \\
    &=& -4 \\ \cmidrule(r{12mm}l{15mm}){1-3}
 3a  &=& 3 \\
  a  &=& 1
\end{array}$
\end{document}

The code works fine for that specific case. However things get easily vertically misaligned. Example: (Same preamble as in previous example.)

\begin{document}
$\begin{array}{r @{\;} c @{\;} l l}
\multirow{2}{*}{$\left\lbrace\begin{array}{@{} r @{\;} c @{\;} r @{}}
 \dfrac{3}{4}a &-& 3b \\
            4a &+& 2b \\
\end{array}\right.$}
    &=& 6  \qquad & ||⋅\dfrac{4}{3} \\
    &=& -2        & ||⋅2 \\
\\
\multirow{2}{*}{$\begin{array}{r} \\ + \\ \end{array}\left\lbrace\begin{array}{@{} r @{\;} c @{\;} r @{}}
a  &-& 4b \\
8a &+& 4b  \\
\end{array}\right.$}
    &=& 8  \\
    &=& -4 \\ \cmidrule(r{12mm}l{15mm}){1-3}
 9a  &=& 4 \\
\end{array}$
\end{document}

Misalignment

I'm looking for a general solution. It would be nice for example if one could make several arrays but define one special delimiter and then stack those arrays on top of each other so that they align at that delimiter.

  • Could you give a specific example of when things "get misaligned"? How should alignment be performed for various tricky cases? – Mico Aug 29 '17 at 19:06
  • @Mico I added example of misaligned equations. In the first picture only things inside a rectangle should be aligned. Rectangles don't need to and generally shouldn't be aligned with each other. There is always only one equals sign on each equation. – Jarno_C-137 Aug 29 '17 at 19:52
2

It seems more natural to use a regular \frac (or \tfrac) rather than \dfrac within a set of equations. With this in mind, you can use eqparbox's \eqmakebox[<tag>][<align>]{<stuff>} to set things in similar-sized boxes. In that way, you can manage the alignment as you see fit. It may be slightly cumbersome, but one can improve on this using collcell's mechanism for capturing a cell's contents.

enter image description here

\documentclass{article}

\usepackage{amsmath,eqparbox}
\newcommand{\mb}[3][r]{\eqmakebox[#2][#1]{$#3$}}

\begin{document}

\[
  \begin{array}{ r @{} l l }
    \mb{c1}{a \cdot (-1)^2} + \mb{c2}{b \cdot (-1)} + \mb{c3}{ c} & {}= \mb{c4}{12} \\
    \smash{\makebox[0pt][r]{$\left\{\begin{array}{@{}c@{}} \mathstrut\\\mathstrut\\\mathstrut\end{array}\right.$}}
    \mb{c1}{a \cdot 0^2}    + \mb{c2}{b \cdot 0}    + \mb{c3}{ c} & {}= \mb{c4}{ 5} \\
    \mb{c1}{a \cdot 2^2}    + \mb{c2}{b \cdot 2}    + \mb{c3}{ c} & {}= \mb{c4}{-3} \\
    \\
                              \mb{c2}{a}            - \mb{c3}{ b} & {}= \mb{c4}{ 7} \\
    \raisebox{.5\normalbaselineskip}[0pt][0pt]{$\left\{\begin{array}{@{}c@{}} \mathstrut\\\mathstrut\end{array}\right.$}
                              \mb{c2}{4a}           + \mb{c3}{2b} & {}= \mb{c4}{-8} & \qquad \Vert:2 \\
    \\
                              \mb{c2}{a}            - \mb{c3}{ b} & {}= \mb{c4}{ 7} \\
    \raisebox{.5\normalbaselineskip}[0pt][0pt]{${}+\left\{\begin{array}{@{}c@{}} \mathstrut\\\mathstrut\end{array}\right.$}
                              \mb{c2}{2a}           + \mb{c3}{ b} & {}= \mb{c4}{-4} \\
    \cline{1-2}
                                                      \mb{c3}{3a} & {}= \mb{c4}{ 3} \\
                                                      \mb{c3}{ a} & {}= \mb{c4}{ 1}
  \end{array}
\]

\[
  \begin{array}{ r @{} l l }
    \mb{c5}{\frac{3}{4}a} - \mb{c6}{3b} & {}= \mb{c7}{ 6} & \qquad \Vert:\frac{4}{3} \\
    \raisebox{.5\normalbaselineskip}[0pt][0pt]{$\left\{\begin{array}{@{}c@{}} \mathstrut\\\mathstrut\end{array}\right.$}
    \mb{c5}{4a}            + \mb{c6}{2b} & {}= \mb{c7}{-2} & \qquad \Vert:2 \\
    \\
    \mb{c5}{a}             - \mb{c6}{4b} & {}= \mb{c7}{ 8} \\
    \raisebox{.5\normalbaselineskip}[0pt][0pt]{$\left\{\begin{array}{@{}c@{}} \mathstrut\\\mathstrut\end{array}\right.$}
    \mb{c5}{8a}            + \mb{c6}{4b} & {}= \mb{c7}{-4} \\
    \cline{1-2}
                             \mb{c6}{9a} & {}= \mb{c7}{ 4}
  \end{array}
\]

\end{document}

Horizontal rules can be adjusted in the same way using booktabs. Also, braces have been fixed outside the \math boxes, but could be included to make them fit better horizontally.

| improve this answer | |
  • The \eqmakebox is new thing for me and it seems to be good way to go. I edited your code to better suit my needs. I'll post my version as an answer below. I think it can still be improved further. – Jarno_C-137 Aug 31 '17 at 23:20
1

This is based on Werners answer but refines it further. It also suits my needs little bit better. Braces work with reqular height rows but if row height increases they don't adjust automatically. Maybe that can also be achieved.

\documentclass{article}

\usepackage{amsmath,eqparbox,xintexpr}

\newcommand{\mb}[3][r]{\eqmakebox[#2][#1]{$#3$}}
\newcommand{\sebrace}[1]{%
    \ifcase#1\or\or%
        \newcommand\NumOfStruts{\mathstrut\\}%
    \or 
        \newcommand\NumOfStruts{\mathstrut\\\mathstrut\\}%
    \or
        \newcommand\NumOfStruts{\mathstrut\\\mathstrut\\\mathstrut\\}%
    \fi
    \raisebox{\xinttheiexpr [1](0.5*((#1)-1))\relax\normalbaselineskip}[0pt][0pt]{%
        $\left\{\begin{array}{@{}c@{}} \NumOfStruts\mathstrut\end{array}\right.$
    }
}

\begin{document}

\[\begin{array}{ r @{\;} l l }
                               \mb{c01}{4x^2} + \mb{c02}{5y} + \mb{c03}{34556c} &= \mb{cy4}{8}  \\
                               \mb{c01}{4x^2} + \mb{c02}{ y} + \mb{c03}{92533c} &= \mb{cy4}{15} \\
                               \mb{c01}{2x^2} + \mb{c02}{6y} + \mb{c03}{  -32c} &= \mb{cy4}{-9} \\
                   \sebrace{4} \mb{c01}{x^2}  + \mb{c02}{5y} + \mb{c03}{     c} &= \mb{cy4}{-5} \\  
    \\
                \mb{c11}{a \cdot (-1)^2} + \mb{c12}{b \cdot (-1)} + \mb{c13}{c} &= \mb{cy4}{12} \\
                \mb{c11}{a \cdot 0^2}    + \mb{c12}{b \cdot 0}    + \mb{c13}{c} &= \mb{cy4}{ 5} \\
    \sebrace{3} \mb{c11}{a \cdot 2^2}    + \mb{c12}{b \cdot 2}    + \mb{c13}{c} &= \mb{cy4}{-3} \\
    \\
                                                    \mb{c22}{ a} - \mb{c23}{ b} &= \mb{cy4}{7} \\
                                        \sebrace{2} \mb{c22}{4a} + \mb{c23}{2b} &= \mb{cy4}{-8} & \qquad \Vert:2 \\
    \\
                                                     \mb{c32}{a } - \mb{c33}{b} &= \mb{cy4}{ 7} \\
                                        +\sebrace{2} \mb{c32}{2a} + \mb{c33}{b} &= \mb{cy4}{-4} \\
                                    \cline{1-2}
                                                                   \mb{c43}{3a} &= \mb{cy4}{3} \\
                                                                   \mb{c43}{ a} &= \mb{cy4}{1} \\
\end{array}\]
\end{document}

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.