Multiple Alignments in flalign

I would like to align the following formula:

\begin{flalign*}
& 100000 & + 1 & = 100001 &\\
& 1      & + 1 & = 2 &\\
\end{flalign*}


I would like the alignment to be just like the text file. So everything left aligned, then some space after 1 in the second row to align the + right underneath the + in the first row. However, what I get is:

How can I remove all this unnecessary space between 100000, 1, and +.

• Is this only one equation which you like to have aligned to left border of text? – Zarko Oct 4 '16 at 18:02
• It's two equations (things with =) that should be aligned to the left border of the text. – Konstantin Weitz Oct 4 '16 at 18:06
• Must the = signs be aligned? – Bernard Oct 4 '16 at 18:15

4 Answers

In my opinion, it doesn't make sense to left align only some equations, so first I provide a version with fleqn

\documentclass{article}

\usepackage[fleqn]{amsmath}
\usepackage{lipsum} % just for the example

\setlength{\mathindent}{0pt} % don't do this, please!

\begin{document}

\lipsum*[2]
\begin{alignat*}{3}
&10000 &&+1  &&= 10001 \\
&1     &&+10 &&= 11
\end{alignat*}
\lipsum[3]

\end{document}


However, setting \mathindent to zero is not something I'd recommend.

If you don't want to use fleqn and just want to left align those equations, you can use alignedat inside flalign:

\documentclass{article}

\usepackage{amsmath}
\usepackage{lipsum} % just for the example

\begin{document}

\lipsum*[2]
\begin{flalign*}
\begin{alignedat}{3}
&10000 &&+1  &&= 10001 \\
&1     &&+10 &&= 11
\end{alignedat}
&&
\end{flalign*}
\lipsum[3]

\end{document}


The output is the same in both cases (other equations without flalign would have different placement, of course).

You could use a TABstack (depending on whether the OP's MWE describes the full requirement or not). The gap is defined with \setstackaligngap{<length>} (default 1em).

NOTE: tabstackengine default alignments require =& rather than &=.

\documentclass[a4paper]{article}
\usepackage{tabstackengine}
\stackMath
\begin{document}
\noindent\alignLongstack{
& 100000 & + 1 = & 100001\\
& 1      & + 1 = & 2\\
}

\setstackaligngap{3em}
\noindent\alignLongstack{
& 100000 & + 1 = & 100001\\
& 1      & + 1 = & 2\\
}
\end{document}


• Thanks! The code works in free floating text, but I'm trying to put it into a float and it breaks with the error: gist.github.com/konne88/5e9d25c2e3818c31cf6b15d9dd8d4a27 – Konstantin Weitz Oct 4 '16 at 18:49
• @KonstantinWeitz A more robust version of tabstackengine is in the works (that copes with the redefinition of \\ ), but in the meantime, you can overcome this problem by choosing a different end-of-line character for the stack: \setstackEOL{\cr} \alignLongstack{ & 100000 & + 1 = & 100001\cr & 1 & + 1 = & 2\cr }. Alternately, you can \let\sveol\\  in the preamble, and then restore that inside the environment: \let\\\sveol \alignLongstack{ & 100000 & + 1 = & 100001\\ & 1 & + 1 = & 2\\ } – Steven B. Segletes Oct 4 '16 at 18:57

Here are 4 different possibilities for a left alignment with \flalign*, and two with the \fleqn environment of nccmath , which allows for a \displayindent:

    \documentclass{article}
\usepackage[showframe]{geometry}%
\usepackage{mathtools, nccmath}
\usepackage{array}
\usepackage{stackengine}
\setstackEOL{\\}

\begin{document}

\begin{flalign*}
\intertext{with \texttt{flalign*}: }
100000 + 1 & = 100001 &\\
1 + 1 & = 2 &
\end{flalign*}

\begin{flalign*}
&    100000 + 1  = 100001 &   \\
&  1 + 1  = 2
\end{flalign*}

\begin{flalign*}
100000   & + 1  = 100001 &    \\
\mathrlap{1}  \phantom{000000}  & + 1  = 2
\end{flalign*}

\begin{flalign*}
\begin{gathered}
100000 + 1  = 100001   \\
1 + 1  = 2
\end{gathered}
& &
\end{flalign*}

\begin{fleqn}[2em]
\begin{align*}
\intertext{with \texttt{fleqn}: }
100000 + 1 & = 100001  \\
1 + 1 & = 2
\end{align*}
\end{fleqn}

\begin{fleqn}[2em]
\begin{gather*}
100000 + 1  = 100001   \\
1 + 1  = 2
\end{gather*}
\end{fleqn}

\end{document}


Try the following:

\documentclass{article}
\usepackage{amsmath}
\setlength{\arraycolsep}{1pt}

% only for demonstrate page layout and show some dummy text
\usepackage{lipsum}
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
%%%%
\begin{document}
\lipsum[2]
\begin{flalign*}
\begin{array}{@{}lll}
100000 & + 1 & = 100001 \\
1      & + 1 & = 2
\end{array} &&
\end{flalign*}
\lipsum[2]
\end{document}


However, if all equations should be lef aligned, thab it is sensible to use option from amsmath, like

\usepackage[fleqn]{amsmath}


which do this for all equations in document.