# Is there a cleaner way to get the proper spacing in this alignedat?

Here's an excerpt from an equation that I'm typesetting. The output is correct and looks how I want it to look.

Here's the MWE that generates this output:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}

\newcommand{\mC}{\mathcal}

\pagestyle{empty}

\begin{document}

\begin{equation*}
\newcommand\spaced[1]{{}#1{}}
\left. \begin{alignedat}{4}
& I_1 &\spaced-&I_2 &\spaced-&I_3 &\spaced=& 0 \\
& I_1 (-2 R_1) &\spaced+& I_2 (-R_2) && &\spaced=& \mC E_1 - \mC E_2 \\
& &&I_2 (R_2) &\spaced+& I_3 (-2 R_1) &\spaced=& \mC E_2 - \mC E_3
\end{alignedat} \right\}
\iff
\text{(more stuff here)}
\end{equation*}

\end{document}


However, I don't like having to include the \spaced commands for each −, +, and = sign in the code. If I don't include it, then the spacing is too tight (because alignedat doesn't include space between columns).

Is there a cleaner way to achieve the correct spacing and alignment? Something like "force binary operator in the even-numbered columns" would be nice.

Would some sort of array environment be a better choice than alignedat?

In this case I would use array:

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{array}

\newcommand{\mC}{\mathcal}

\pagestyle{empty}

\begin{document}

\begin{equation*}
\left.\setlength{\arraycolsep}{0pt}\renewcommand{\arraystretch}{1.2}
\begin{array}{l >{{}}c<{{}} l >{{}}c<{{}} l >{{}}c<{{}} l}
I_1         &-& I_2       &-& I_3         &=& 0 \\
I_1(-2 R_1) &+& I_2(-R_2) & &             &=& \mC E_1 - \mC E_2 \\
& & I_2(R_2)  &+& I_3(-2 R_1) &=& \mC E_2 - \mC E_3
\end{array} \right\}
\iff
\text{(more stuff here)}
\end{equation*}

\end{document}


The additional columns >{{}}c<{{}} add the correct spacing around the binary operators. The settings to \arraycolsep and \arraystretch are local in the \left\right group.

• Neat, thanks! I added a \newcolumntype{o}{>{{}}c<{{}}} within the equation* (o for "operator"), so then you can just write \begin{array}{lololol} (which has the added benefit of looking amusing). – wchargin May 10 '15 at 19:39
• @WChargin LOLOLOL! – egreg May 10 '15 at 19:51

you can use alignedat with some small modifications. remove the ampersands following the signs of operation and relation and then double all ampersands after the first. the positioning by ampersands alternations -- right/left -- as "equalities" are assumed.

if an "indented" element isn't preceded by a sign of operation or relation, then it will have to be spaced over to compensate. i've redefined \spaced to do "the right thing" if all operators are the same size (plus, minus and equals are).

\documentclass{article}

\usepackage{amsmath}
\usepackage{amsfonts}

\newcommand{\mC}{\mathcal}
%\newcommand\spaced[1]{{}#1{}}
\newcommand\spaced{\phantom{{}+{}}}

\pagestyle{empty}

\begin{document}

\begin{equation*}
\left. \begin{alignedat}{4}
& I_1 &&-I_2 &&-I_3 &&= 0 \\
& I_1 (-2 R_1) &&+ I_2 (-R_2) && &&= \mC E_1 - \mC E_2 \\
& &&\spaced I_2 (R_2) &&+ I_3 (-2 R_1) &&= \mC E_2 - \mC E_3
\end{alignedat} \right\}
\iff
\text{(more stuff here)}
\end{equation*}

\end{document}


• I considered something like this, but assumed (wrongly, apparently) that the spacing after the I_1 (-2 R_1) on the second row would be too small because there's no atom to the left of the + sign (because it's in the next column). Could you explain why this isn't the case? – wchargin May 10 '15 at 19:51
• @WChargin -- the "multi-column" multi-line environments defined by amsmath always assume that an operator will follow an & sign and compensate, pretending that the operator is preceded by an atom to its left. thus, the user need only compensate explicitly when a unary operator is involved; in that case, enclosing the operator (usually - or +) in braces to make it an "ordinary" atom. – barbara beeton May 10 '15 at 20:15
• It would even look better writing &&+\mathrlap{I_1(-R_2)} in the second line. – Bernard May 10 '15 at 22:04
• @Bernard hmm…this causes the end of (-R_2) to protrude into the operator column, which looks a bit off to me. Although the spacing on the bottom row is nicer, overall it breaks the flow in my opinion. – wchargin May 10 '15 at 23:46

I didn't do any change in your data area, I only replaced your \begin{alignedat}{4} by \vcenter{...\haling{... and your \end{alignat} by }}. Only the \\ in the last line is added. Your aligned material is solved by simple TeX primitive \halign:

  \left. \vcenter{\let\\=\cr \halign{&${}#{}$&$#$\hfil\cr
& I_1 &-&I_2 &-&I_3 &=& 0 \\
& I_1 (-2 R_1) &+& I_2 (-R_2) && &=& \mC E_1 - \mC E_2 \\
& &&I_2 (R_2) &+& I_3 (-2 R_1)   &=& \mC E_2 - \mC E_3 \\
}} \right\}

• Interesting—I haven't used \halign before. I almost understand how it works. Is the alignment specification cyclic? If I'm interpreting it correctly, you've only defined two columns, and yet the eight columns in the data area are easily displayed. So will TeX cycle through the column specifiers as many times as required? Also, what's the purpose of the \hfil? – wchargin May 10 '15 at 20:10
• @WChargin Yes, the alignment specification is cyclic when very first character is & (this case) or it cycles from the end of specification to && if double && is used (not used here). And \hfil is stretchable space, used at the right side of the specification of the column: it means that this column will be aligned left. – wipet May 10 '15 at 20:15