49

Is there a way possible to imitate the align environment for math mode commands, without having all writing being placed toward the center on the output page?

MWE:

\documentclass{article}
\usepackage{mathtools}

\begin{document}
\begin{align*}
\cos\theta_1 \cos\theta_2-\sin\theta_1\sin\theta_2 &= \cos(\theta_1 +\theta_2) \\
\sin\theta_1 \cos\theta_2 + \cos\theta_1 \sin\theta_2 &= \sin(\theta_1+\theta_2)
\end{align*}

\end{document}
David Carlisle
  • 757,742
night owl
  • 7,593
  • It's not clear by what you mean by without having everything being centered on the output page. For one, it is the gather and gather* environments rather than the align and align* environments which center their output on a line. – Mico Sep 16 '11 at 10:51
  • 1
    is there a reason you are adding spaces \; around the equal signs? this wide spacing is reminiscent of what is produced by \eqalign, and it's not considered good style in mathematics publications. – barbara beeton Sep 16 '11 at 14:39

3 Answers3

77

As Andrew mentions you can use \usepackage[fleqn]{amsmath}, but this will mean tha all you equations will be moved to the left.

However, if you want to be able to have some centered and some on the left, then you can use the flalign environment. But, note the trailing & that is required when this is used. As mentioned by egreg, the trailing & in the flalign environment is only required in one of the lines.

\documentclass{article}
\usepackage{amsmath}% mathtools includes this so this is optional
\usepackage{mathtools}

\begin{document}
\begin{align*}% centered
\cos\theta_1 \cos\theta_2-\sin\theta_1\sin\theta_2 &= \cos(\theta_1 +\theta_2) \\
\sin\theta_1 \cos\theta_2 + \cos\theta_1 \sin\theta_2 &= \sin(\theta_1+\theta_2)
\end{align*}

\begin{flalign*}% left aligned
\cos\theta_1 \cos\theta_2-\sin\theta_1\sin\theta_2 &= \cos(\theta_1 +\theta_2) &\\
\sin\theta_1 \cos\theta_2 + \cos\theta_1 \sin\theta_2 &= \sin(\theta_1+\theta_2) &% Need tailing alignment char to get all the way left
\end{flalign*}
\end{document}

I removed the \; from the OP's MWE, which inserted additional spacing where it was not necessary.

Peter Grill
  • 223,288
  • 2
    One can add, say, \qquad in front of the first line in order not to get left flushing; the trailing & is needed only in one of the lines. Note that those \; commands are wrong. – egreg Sep 16 '11 at 13:18
  • Nice to know about that. (To produce the picture in my (updated) answer, I introduced a \fleqn hack that reset stuff according to the fleqn option. If I'd known about falign ...) – Andrew Stacey Sep 16 '11 at 13:19
  • @egreg: Totally agree. I noticed those, but since it appeared that \; were intentionally added, it was the OPs style of choice to have additional space. – Peter Grill Sep 16 '11 at 13:25
  • @Andrew: Wow!! Can't believe that I was actually able to teach you something.. – Peter Grill Sep 16 '11 at 13:26
  • egreg, Peter: So how should one do correct spacing for something as so? I'm open to new ways. – night owl Sep 16 '11 at 17:27
  • 1
    Just remove the \; and you'll get the "correct" spacing. It is preferable to let TeX determine the spacing so that it is consistent. I have removed them form this answer in case others see this and think that they should be there. – Peter Grill Sep 16 '11 at 17:30
  • Peter: Is there an option analogous to the left align for right align, for e.g. fralign? – night owl Oct 09 '11 at 22:10
  • Best to post a separate question as someone in the future may benefit from it... – Peter Grill Oct 10 '11 at 02:25
  • Does this work with the beamer class? (I ask because after a quick attempt it did not seem to, at least not with the typical packages I use). Oh wait, this weird combo of & and && worked: https://tex.stackexchange.com/questions/364332/flalign-doesnt-work-in-beamer – PatrickT Sep 16 '17 at 13:40
35

The amsmath package has a fleqn option which, according to the manual (texdoc amsmath) has the following effect:

Position equations at a fixed indent from the left margin rather than centered in the text column.

Thus:

\usepackage[fleqn]{amsmath}

seems to be what you are after.

The mathtools package loads amsmath internally and passes any unknown arguments on to it. This includes the fleqn option. Thus:

\usepackage[fleqn]{mathtools}

also works.

Here's a comparison of the outputs. The upper one is without fleqn and the lower one with.

fleqn option

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
  • 1
    Andrew, Thanks. So is there an option for this as well using the mathtools package or is it already built in somehow? – night owl Sep 16 '11 at 12:32
  • 1
    @night owl: I didn't realise you were using mathtools. As that loads amsmath it's easy to adapt my answer to that case. I've updated my answer. – Andrew Stacey Sep 16 '11 at 13:17
  • 5
    @AndrewStacey I just tried this, but my equations do not get flushed entirely to the left (there is still some margin on the left hand side). What could I try to remove this remaining margin? – texfan Nov 13 '13 at 18:22
  • 2
    @texfan: You can use \setlength{\mathindent}{1cm} under the fleqn command. – Maverick May 31 '22 at 18:47
17

I'm not sure what you mean by "immitate", but I guess you mean you don't want the equations centered, but aligned in another way. A MWE would have been nice, to better understand your problem, to know what documentclass you are using, etc. Anyway, you can have equations aligned differently with align, if you load the amsmath package and write something like this:

\documentclass[a4paper,10pt,fleqn]{article}
\usepackage{amsmath}
\setlength{\mathindent}{1cm}
\begin{document}
\noindent Blah
\begin{align*}
y = ad + da\\
y = ad + da
\end{align*}
\end{document}

As you probably guessed, \setlength{\mathindent}{1cm} lets you control the indentation.

David Carlisle
  • 757,742
Count Zero
  • 17,424