# How to reduce hspace between columns in align environment

With the following MWE, I have 2 columns:

\documentclass[12pt, a4paper]{scrartcl}
\usepackage{amsmath}
\begin{document}
\begin{align*}
4   &= 4 && \text{yes}\\
0   &= 0 && \text{no}\\
1+1 &= 2 && \text{maybe}
\end{align*}
\end{document}


But I would like to control the hspace between the 2 columns, possibly, with only one command call for the whole align, rather than one for each line.

You can use the alignat environment, that gives full control over the alignment:

\begin{alignat*}{2}
\end{alignat*}


Actually only the widest entry in the second column needs the padding, but it's easier to specify it on each one.

The "2" refers to the number of "left hand side-right hand side" groups you need.

A more general solution is to define a new environment:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{environ}
\makeatletter
\newdimen\royalignsep@
\def\royalign@preamble{%
&\hfil
\strut@
\setboxz@h{\@lign$\m@th\displaystyle{##}$}%
\ifmeasuring@\savefieldlength@\fi
\set@field
\tabskip\z@skip
&\setboxz@h{\@lign$\m@th\displaystyle{{}##}$}%
\ifmeasuring@\savefieldlength@\fi
\set@field
\hfil
\tabskip\royalignsep@
}
\NewEnviron{royalign}[1]{%
\royalignsep@=#1\let\align@preamble=\royalign@preamble
\begin{align}\BODY\end{align}}
\NewEnviron{royalign*}[1]{%
\royalignsep@=#1\let\align@preamble=\royalign@preamble
\begin{align*}\BODY\end{align*}}
\makeatother
\pagestyle{empty}
\begin{document}

\begin{royalign*}{1cm}
4   &= 4 & 1+3+5 &= 9\\
0   &= 0 & 2+1   &= 3\\
1+1 &= 2 & 1     &= 1
\end{royalign*}
\end{document}


You have both royalign and royalign*; you can check that the spacing is exactly what you specify in the argument.

• yes, this solution is good for the situation "one column of equations + one column of text". But for two column of equations, this is not optimal, since one has to put a hspace which depends on the largest entry of the right hand side terms of the left hand side column. I would prefer to say " i want 1 cm between the 2 columns of equations", independently of their content. Am i clear ? – nicolas roy Jan 5 '12 at 17:30
• by the way, i don't see any influence of the parameter "2"... – nicolas roy Jan 5 '12 at 17:35
• @nicolasroy See edit. – egreg Jan 5 '12 at 18:10
• My apologize for being so late in answering. Thanks for the solution, it works very well. Could you just tell me, why you use \NewEnviron ? What does it bring in contrast to \newenvironment{royalign}{\royalignsep@ ... \begin{align}}{\end{align}} – nicolas roy Jan 9 '12 at 20:32
• @nicolasroy It's the usual problem about align, where TeX has to "see" the precise sequence of tokens \end{align} in order to decide when the environment ends, since it has to collect the contents and measure it. Actually, \NewEnviron is inspired by amsmath's method: it collects the environments contents and, in this case, it passes it to align. – egreg Jan 9 '12 at 20:35

use the old xalignat environment if it could be left aligned

\documentclass[12pt, a4paper]{scrartcl}
\usepackage{amsmath}
\begin{document}
\begin{xalignat*}
4   &= 4 && \text{yes}\\
0   &= 0 && \text{no}\\
1+1 &= 2 && \text{maybe}
\end{xalignat*}
\end{document}