2

I am trying to put several matrices within an align environment so that even though they are of different width, all the equal signs in them align across. Here is my code:

\documentclass[12pt]{article}
\usepackage{latexsym}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{mathtools}

\begin{document}
\begin{align*}
\left\{ \begin{matrix*}[l]
x_0&=3\\ 
x_1&=1
\end{matrix*}\right.\\[2ex]
\left\{ \begin{matrix}
c_12^0+c_2\cdot0\cdot2^0&=3\\
c_12^1+c_2\cdot1\cdot2^1&=1
\end{matrix}\right.\\[2ex]
\left\{ \begin{matrix}
c_1&=3\\
2c_1+2c_2&=1
\end{matrix}\right.\\[2ex]
\left\{ \begin{matrix*}[l]
c_1&=3\\
c_2&=(1-2\cdot 3)/2\\
&=(-5)/2\\
&=-\frac{5}{2}
\end{matrix*}\right.
\end{align*}

\end{document}

which outputs the following:

enter image description here

I don't get how my first 3 matrices do exactly what I want, but my fourth matrix doesn't lineup at the equal signs, even though I am doing the same thing as I did for the first 3 matrices which worked.

  • @DavidCarlisle I'm sorry I accidentally posted an old wrong code. I've updated it. idk if this is what you mean by compilable code. – Carina Chen Mar 25 at 9:57
  • Yes thanks, I deleted previous comments, people can now test it – David Carlisle Mar 25 at 10:00
  • I'm afraid you have to use a different approach. If you add more digits to "3" or "1", you will see the disadvantage. – user156344 Mar 25 at 10:01
  • 1
    Have a look at egreg's answer. – user156344 Mar 25 at 10:03
2

matrix is designed for matrices of values, not aligned equations (notably it is set in inline math mode not display style) also your right hand only "accidentally" aligned in the first three cases as all the entries were a single digit. I would set the entire display as an align* to get display math mode and aligned = and then drop in the { " by hand".

enter image description here

\documentclass[12pt]{article}
\usepackage{latexsym}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{mathtools}

\begin{document}
\begin{align*}
\smash{\raisebox{-10pt}{$\left\{\rule{0pt}{1.2\normalbaselineskip}\right.$}}
x_0&=3\\ 
x_1&=1\\[\jot]
\smash{\raisebox{-10pt}{$\left\{\rule{0pt}{1.2\normalbaselineskip}\right.$}}
c_12^0+c_2\cdot0\cdot2^0&=3\\
c_12^1+c_2\cdot1\cdot2^1&=1\\[\jot]
c_1&=3\\
\smash{\raisebox{2pt}{$\left\{\rule{0pt}{1.2\normalbaselineskip}\right.$}}
2c_1+2c_2&=1\\[\jot]
\smash{\raisebox{-35pt}{$\left\{\rule{0pt}{2.9\normalbaselineskip}\right.$}}
c_1&=3\\
c_2&=(1-2\cdot 3)/2\\
&=(-5)/2\\
&=-\frac{5}{2}
\end{align*}

\end{document}
1

with nicematrix:

\documentclass[margin=3mm, varwidth]{standalone}
\usepackage{nicematrix}
\usetikzlibrary{decorations.pathreplacing,
                calligraphy}
\tikzset{
B/.style = {decorate,
            decoration={calligraphic brace, amplitude=4pt,
            raise=1pt, mirror},% for mirroring of brace
            thick,
            pen colour=black}
        }

\begin{document}
    \[\setlength\arraycolsep{1pt}
\begin{NiceArray}{RCL}%
    [code-after={\tikz\draw[B] (1-1.north west) -- (2-1.south west);
                 \tikz\draw[B] (3-1.north west) -- (4-1.south west);
                 \tikz\draw[B] (5-1.north -| 6-1.west) -- (6-1.south west);
                 \tikz\draw[B] (7-1.north west) -- (7-1.west |- 10-1.south);
                }
    ]
x_0 & = & 3     \\
x_1 & = & 1     \\[\jot]
%
c_12^0+c_2\cdot0\cdot2^0 & = & 3    \\
c_12^1+c_2\cdot1\cdot2^1 & = & 1    \\[\jot]
%
c_1       & = & 3   \\
2c_1+2c_2 & = & 1   \\[\jot]
%
c_1 & = & 3\\
c_2 & = & (1-2\cdot 3)/2\\
    & = & (-5)/2\\
    & = & -\frac{5}{2}
\end{NiceArray}
    \]
\end{document}

you need to compile document at least twice.

enter image description here

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.