# Decipher a code for an array environment

I saw on this web site two codes to get vertical alignment at the equals signs in consecutive systems of equations. One of them uses the systeme package and the \mathrlap command for the quantity on the right side of each equals sign. Another uses the array environment. It is more cumbersome, but I would like to be more familiar with this environment. Here is the code.

{\settowidth{\widestright}{${}=#1$}
\left\{
\begin{array} {@{}r@{}>{\raggedright\arraybackslash${}}p{\widestright}<{$}@{}}}
{\end{array}
\right.}


(It was implemented as part of a \newcommand in the preamble. I do not want it in the preamble. So, I know that I will not need the ${}=#1$.) I understand that the \settowidth command sets the value of a length command equal to the width of the text argument. I have not seen it used with \widestright except in this code. What does \settowidth{\widestright} instruct LaTeX to typeset? What is

>{\raggedright\arraybackslash${}}p{\widestright}<{$}


in the array environment instructing LaTeX to print? In particular, what are \arraybackslash, \widestright, and > and < instructing LaTeX to print? How do I implement it - or an appropriate modification of it - to get the alignment at the equals signs?

Here is the code for the systems of linear equations.

\documentclass[10pt]{amsart}
\usetikzlibrary{calc,angles,positioning,intersections,quotes,decorations.markings}
\usepackage{mathtools,array}

\usepackage{pgfplots}
\pgfplotsset{compat=1.11}

\begin{document}

\begin{gather*}
\left\{
\begin{array}{@{}c@{}c@{}c@{}c@{}c}
-3x &   {}-{}   &   6y  &   {}={}   &   -15 \\
3x  &   {}+{}   &   4y  &   {}={}   &   6
\end{array}
\right.
, \\
\left\{
\begin{array}{@{}r@{}c@{}l}
-3x - 6y    &   {}={}    &   -15 \\
-2y         &   {}={}    &   -9
\end{array}
\right.
, \\
\left\{
\begin{array}{@{}r@{}c@{}l}
x + 2y  &   {}={}   &   5 \\
y       &   {}={}   &   9/2
\end{array}
\right.
, \\
\left\{
\begin{array}{@{}r@{}c@{}l}
x   &   {}={}   &   -4 \\
y   &   {}={}   &   9/2
\end{array}
\right.
.
\end{gather*}

\end{document}

• I don't know when and how this started but a left unbalanced brace pointing to nothing is pretty useless and ugly notation to group your equations. Try matrices or interspacing to group the steps. – percusse Nov 27 '14 at 19:35
• @percusse It is standard notation for a system of linear equations. It is what I want. – Adelyn Nov 27 '14 at 19:38
• I don't know any such standards. And I'm working on linear algebra. – percusse Nov 27 '14 at 19:43

• \settowidth takes two arguments. The first is a length (or dimension) <len> (say) and the second is <something>. <something> is placed inside a box, which can be measured, and then the width of that box is assigned to the length <len>. So,

\settowidth{\widestright}{abc}


will assign the width of the string abc to the length \widestright. \widestright is most likely defined using \newlength{\widestright}.

• The array package provides two new directives when it comes to the column specification of an array or tabular. These directives have the form >{<stuff>} and <{<stuff>}. The > is meant to insert content at the beginning of each cell, while < is used to insert content at the end of each cell in that particular column. So

>{\raggedright\arraybackslash${}}  inserts \raggedright\arraybackslash${} at the beginning of every cell. As such, each cell will have a \raggedright alignment and an inline-math environment is started (due to the insertion of $). Similarly, <{$}


inserts an ending $ to close the inline-math environment. See below for \arraybackslash. Collectively then, the column specification >{\raggedright\arraybackslash${}}p{\widestright}<{$}  makes every cell in that column have a specific width of \widestright (since it's using a p{<len>} column) that starts with \raggedright\arraybackslash${} and ends with $. The use case is to make a p-column (which is typically set in text-mode) a math-mode column. Use of ${}... is to achieve proper horizontal alignment between certain operators that have different spacing if used in a binary/unary fashion (like -; see how different {}-x$ sets from $-x). • \arraybackslash is used to restore certain qualities of the \\ used to denote a new line in array or tabular. The array package defines this to correct behaviour inserted with other alignment properties like \raggedright, \raggedleft and \centering. So, typically one should issue \arraybackslash after using any of the preceding alignment changes before you reach the end of the row \\. I might set the system of aligned linear equations in the following way: \documentclass{article} \usepackage{mathtools} \begin{document} \begin{align*} \raisebox{-.5\height}[0pt][0pt]{\biggl\{$} {-}3x - 6y &= -15 \\ 3x + 4y &= \phantom{-15}\mathllap{6} \\[\jot] \raisebox{-.5\height}[0pt][0pt]{$\biggl\{$} {-}3x - 6y &= -15 \\ -2y &= \phantom{-15}\mathllap{-9} \\[\jot] \raisebox{-.5\height}[0pt][0pt]{$\biggl\{$} \phantom{-3}x + 2y &= \phantom{-15}\mathllap{5} \\ y &= \phantom{-15}\mathllap{9/2} \\[\jot] \raisebox{-.5\height}[0pt][0pt]{$\biggl\{} \phantom{-3}x \phantom{{}+2y} &= \phantom{-15}\mathllap{-4} \\ y &= \phantom{-15}\mathllap{9/2} \end{align*} \end{document}  Since the braces aren't allowed across groups, they're manually positioned into place. One may also consider a set of cases. • Thanks for your careful explanation. I would appreciate your efforts in implementing this code to get the vertical alignment at the equals signs in the given consecutive systems of equations. Seeing it implemented would illustrate your explanations. (I have some questions regarding some of your explanations which prevents me from implementing the code myself.) – Adelyn Nov 27 '14 at 16:21 • @Adelyn: See my updated answer. – Werner Nov 27 '14 at 16:50 • @ Werner Your previous code gave me exactly what I wanted. Take a look at the answer provided at the following web site. He defines a new command in the preamble. That does not help me understand the features of the array environment. tex.stackexchange.com/questions/193581/… – Adelyn Nov 27 '14 at 18:25 • @Adelyn: Okay, what are you referring to when you say "previous code"? Is that the update to my answer or what I had written previously without the update. Also, the use of a new command that accepts some argument and processes it is good style. So... could you clarify what you mean by your last comment? – Werner Nov 27 '14 at 18:30 • Sorry. I should not have said "previous code." I liked your explanations. I understand that putting a new command in the preamble is nicer because it reduces significantly the number of lines of code needed. Right now, I am interested in learning about the array environment. If I saw how you implement the features of the array environment that you described to the specific systems of equations that I provided to get the display that I want, I may get more familiar with it. By the way, the left brace should move to the right in succeeding systems. See the web site that I provided. – Adelyn Nov 27 '14 at 19:31 (Answer re-written to provide a pure array-based solution.) Here's an array-based way to typeset your systems of equations. As you'll see, the array's header is a bit different from the one you provide in your posting; the changes are made to simplify entering the material in the bodies of the array environments. Some explanations are in order: • The array package is loaded, as it provides extra tools for setting up column types and for influencing what goes between the columns. • To typeset the material to the right of the equal sign, a new column type, named R (note the use of the Uppercase Letter), is defined as follows: \newcolumntype{R}{>{\raggedleft\arraybackslash} p{\mylen} <{$}}  The macro \newcolumntype is provided by the array package. The R column is a modified form of the p column, with the following two modifications: (i) the material will be typeset automatically in math mode; (ii) the material will be set flushright -- hence the letter R. Finally, the directive \arraybackslash re-enables the usual meaning of the \\ line-breaking command. (If you don't provide this directive, you'll have to write \tabularnewline lots of times...) • The width of the R column is \mylen, where \mylen is set in the preamble to the width of $-15$, the single widest element to the right of the equal signs. • Each array header is specified as follows: {@{} r @{} >{{}}c<{{}} @{} r @{{}={}} R}  What do these things mean? (i) @{} means "no inter-column whitespace"; (ii) r and R mean exactly what you think they mean; (iii) >{{}}c<{{}} means "insert {} at the start of the column (of type c) and insert {} at the end of the column" -- this will save you from having to type lots of {}+{} and {}-{} constructs in the body of the array; and @{{}={}} means "insert an = symbol surrounded by {} (empty math atoms) on either side -- this saves you from having to type the equal signs in the body of the array. • With this setup, entering the material for each system of equations is quite straightforward. For instance, the first system of equations is entered as  -3x & - & 6y & -15 \\ 3x & + & 4y & 6  Only in the final system of equations is there a need for lots of \phantoms. • Two more items to mention: The parameter \arraystretch is set to 1.25 to mimic the look of displayed equations; and the spacing between consecutive arrays is increased by [1ex]. Change both of the choices, if desired, to suit your needs. \documentclass{amsart} % loads amsmath package, which provides gather* environment \newlength\mylen \settowidth\mylen{$-15$} %% use widest element to the right of = signs \usepackage{array} \newcolumntype{R}{>{\raggedleft\arraybackslash$} p{\mylen} <{$}} \begin{document} \renewcommand{\arraystretch}{1.25} \begin{gather*} \Bigg\{ \begin{array}{@{} r @{} >{{}}c<{{}} @{} r @{{}={}} R} -3x & - & 6y & -15 \\ 3x & + & 4y & 6 \end{array} \\[1ex] \Bigg\{ \begin{array}{@{} r @{} >{{}}c<{{}} @{} r @{{}={}} R} -3x & - & 6y & -15 \\ & - & 2y & -9 \end{array}\\[1ex] \Bigg\{ \begin{array}{@{} r @{} >{{}}c<{{}} @{} r @{{}={}} R} \phantom{-3}x & + & 2y & 5 \\ & & y & 9/2 \end{array} \\[1ex] \Bigg\{ \begin{array}{@{} r @{} >{{}}c<{{}} @{} r @{{}={}} R} \phantom{-3}x & \phantom{{}+{}}& & -4 \\ & & \phantom{2}y & 9/2 \end{array} \end{gather*} \end{document}  • Code using the systeme environment that gives me exactly what I want is provided at the following web site. I want to get the same display using the array environment. (See my comments to Werner.) tex.stackexchange.com/questions/213942/… – Adelyn Nov 27 '14 at 19:35 • @Adelyn - I've rewritten my answer to provide a "pure" array-based solution. – Mico Nov 27 '14 at 21:19 • Thanks for the code. At least now I can mimic that in other systems of linear equations. I have some specific questions that would clarify the code for me. The array package provides two new directives regarding column specification of an array environment. These directives have the form >{<blah>} and <{<blah>}. The > is meant to insert content at the beginning of each cell, while < is used to insert content at the end of each cell in that particular column. So, >{\raggedright\arraybackslash${}} inserts \raggedright\arraybackslash{} at the beginning of every cell. – Adelyn Nov 28 '14 at 17:02 • As such, each cell will have a \raggedright alignment and will start with an inline-math environment (due to the insertion of ""). Similarly, {$} inserts an ending$ to close the inline-math environment. Here is one question. Why is the "$" before "{}" in one case and in "{}" in another case? The code provided by Werner has the same "thing." – Adelyn Nov 28 '14 at 17:05 • @Adelyn - That's indeed what the >{...} and <{...} directives do. Thus, if a tabular environment is used, material in a column set up as >{$}c<{$} will be treated as being in math mode by default (and will be set centered); without the >{$} and <{$} elements, the material in that column would be treated as being in text mode by default. Even in an array environment, material in a p column is treated as being in text mode by default; the $ elements in the openers and closers instruct LaTeX to treat the material as being in math mode instead. This saves having to type \$... – Mico Nov 28 '14 at 17:08