Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
You could use an array environment instead and then {rl@{\quad}l} for the column specificator. –  Martin Scharrer Jan 5 '12 at 10:47
1  
Have you seen this Question stackoverflow.com/questions/4361275/… ? it at least is able to reduce the space between the first 3 columns (your equations) and the second column, where you put the text. –  Ronny Jan 5 '12 at 10:49
    
@Ronny The question is also on TeX.SX: tex.stackexchange.com/questions/6572/… –  egreg Jan 5 '12 at 11:56
add comment

2 Answers

up vote 7 down vote accepted

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

\begin{alignat*}{2}
4   &= 4\qquad && \text{yes}\\
0   &= 0\qquad && \text{no}\\
1+1 &= 2\qquad && \text{maybe}
\end{alignat*}

enter image description here

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.

share|improve this answer
    
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
show 3 more comments

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}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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