8

I want to display four equations which have different length. I want they align left like this.enter image description here

But my code give thisenter image description here

The following are my code:

$$\begin{aligned} p(a) &=p(a) p(a \rightarrow a)+p(b) p(b \rightarrow a)+p(c) p(c \rightarrow a)+p(d) p(d \rightarrow a) \\  
&={\scriptstyle \frac{1}{2} \frac{2}{3}+\frac{1}{4} \frac{1}{3}+\frac{1}{3}+\frac{1}{3}=\frac{1}{2}}
\end{aligned}$$
$$\begin{aligned} p(b) &=p(a) p(a \rightarrow b)+p(b) p(b \rightarrow b)+p(c) p(c \rightarrow b) \\ 
&={\scriptstyle\frac{1}{2} \frac{1}{6}+\frac{1}{4} \frac{1}{2}+\frac{1}{3} \frac{1}{3}=\frac{1}{4}} \end{aligned}$$
$$\begin{aligned} p(c) &=p(a) p(a \rightarrow c)+p(b) p(b \rightarrow c)+p(c) p(c \rightarrow c)+p(d) p(d \rightarrow c) \\ 
&={\scriptstyle\frac{1}{2} \frac{1}{12}+\frac{1}{4} \frac{1}{6}+\frac{1}{8} 0+\frac{1}{8}=\frac{1}{8}} \end{aligned}$$
$$\begin{aligned} p(d) &=p(a) p(a \rightarrow d)+p(c) p(c \rightarrow d)+p(d) p(d \rightarrow d) \\ 
&={\scriptstyle\frac{1}{2} \frac{1}{12}+\frac{1}{8} \frac{1}{3}+\frac{1}{8} \frac{1}{3}=\frac{1}{3}} \end{aligned}$$

Can anyone tell me what I can do?

  • never use $$ in latex, use \[ and then the fleqn option will left align equations. – David Carlisle Mar 22 at 8:45
7

Here is a proposal

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
p(a)&=p(a) p(a \rightarrow a)+p(b) p(b \rightarrow a)+p(c) p(c \rightarrow a)+p(d) p(d \rightarrow a)\\
&\;={\scriptstyle \frac{1}{2} \frac{2}{3}+\frac{1}{4} \frac{1}{3}+\frac{1}{3}+\frac{1}{3}=\frac{1}{2}}\\
p(b)&=p(a) p(a \rightarrow b)+p(b) p(b \rightarrow b)+p(c) p(c \rightarrow b)\\
&\;={\scriptstyle\frac{1}{2} \frac{1}{6}+\frac{1}{4} \frac{1}{2}+\frac{1}{3} \frac{1}{3}=\frac{1}{4}}\\
p(c)&=p(a) p(a \rightarrow c)+p(b) p(b \rightarrow c)+p(c) p(c \rightarrow c)+p(d) p(d \rightarrow c)\\
&\;={\scriptstyle\frac{1}{2} \frac{1}{12}+\frac{1}{4} \frac{1}{6}+\frac{1}{8} 0+\frac{1}{8}=\frac{1}{8}}\\
p(d)&=p(a) p(a \rightarrow d)+p(c) p(c \rightarrow d)+p(d) p(d \rightarrow d)\\
&\;={\scriptstyle\frac{1}{2} \frac{1}{12}+\frac{1}{8} \frac{1}{3}+\frac{1}{8} \frac{1}{3}=\frac{1}{3}}
\end{align*}
\end{document}

enter image description here

Why do you use \scriptstyle? It is very hard to read the fractions! Use \tfrac instead!

You should remove \; in the &\;={\scriptstyle... lines to align the =s. I prefer that way.


I strongly recommend this one

\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
p(a)&=p(a) p(a \rightarrow a)+p(b) p(b \rightarrow a)+p(c) p(c \rightarrow a)+p(d) p(d \rightarrow a)\\
&=\tfrac{1}{2} \tfrac{2}{3}+\tfrac{1}{4} \tfrac{1}{3}+\tfrac{1}{3}+\tfrac{1}{3}=\tfrac{1}{2}\\
p(b)&=p(a) p(a \rightarrow b)+p(b) p(b \rightarrow b)+p(c) p(c \rightarrow b)\\
&=\tfrac{1}{2} \tfrac{1}{6}+\tfrac{1}{4} \tfrac{1}{2}+\tfrac{1}{3} \tfrac{1}{3}=\tfrac{1}{4}\\
p(c)&=p(a) p(a \rightarrow c)+p(b) p(b \rightarrow c)+p(c) p(c \rightarrow c)+p(d) p(d \rightarrow c)\\
&=\tfrac{1}{2} \tfrac{1}{12}+\tfrac{1}{4} \tfrac{1}{6}+\tfrac{1}{8} 0+\tfrac{1}{8}=\tfrac{1}{8}\\
p(d)&=p(a) p(a \rightarrow d)+p(c) p(c \rightarrow d)+p(d) p(d \rightarrow d)\\
&=\tfrac{1}{2} \tfrac{1}{12}+\tfrac{1}{8} \tfrac{1}{3}+\tfrac{1}{8} \tfrac{1}{3}=\tfrac{1}{3}
\end{align*}
\end{document}

enter image description here

  • Thank you very much. I use '\scriptstyle' because I want the second line of the equation to be small. – chole Mar 22 at 8:55
  • 1
    @chole Then you should use \tfrac instead of \scriptstyle\frac. – JouleV Mar 22 at 8:58
  • 2
    +1 for recommending \tfrac in place of \scriptstyle\frac. – Mico Mar 22 at 9:00
  • @chole If my answer helps you, please mark your question as resolved by clicking the checkmark on the left of my answer. – JouleV Mar 22 at 9:02
  • 1
    +1 yes as I commented under the question the direct answer why there was no left alignment was due to using $$ but If I had answered I would also have suggested align* rather than \[\begin{aligned} :-) – David Carlisle Mar 22 at 9:08
6

I propose this layout, using the fleqn environment and, as in my opinion, medium sized fractions will look best, I also use the \medmath and \mfrac commands, each from nccmath:

\documentclass{article}
\usepackage{amsmath, nccmath}

\begin{document}

\begin{fleqn}
\begin{align*}
p(a)&=p(a) p(a \rightarrow a)+p(b) p(b \rightarrow a)+p(c) p(c \rightarrow a)+p(d) p(d \rightarrow a)\\
&\quad= \medmath{\frac{1}{2}\cdot \frac{2}{3}+\frac{1}{4}\cdot \frac{1}{3}+\frac{1}{3}+\frac{1}{3}}=\mfrac{1}{2} \\[1ex]
p(b)&=p(a) p(a \rightarrow b)+p(b) p(b \rightarrow b)+p(c) p(c \rightarrow b)\\
&\quad= \medmath{\frac{1}{2}\cdot \frac{1}{6}+\frac{1}{4}\cdot \frac{1}{2}+\frac{1}{3}\cdot \frac{1}{3}}=\mfrac{1}{4} \\[1ex]
p(c)&=p(a) p(a \rightarrow c)+p(b) p(b \rightarrow c)+p(c) p(c \rightarrow c)+p(d) p(d \rightarrow c)\\
&\quad= \medmath{\frac{1}{2}\cdot \frac{1}{12}+\frac{1}{4}\cdot \frac{1}{6}+\frac{1}{8}\,0 + \frac{1}{8}}=\mfrac{1}{8} \\[1ex]
p(d)&=p(a) p(a \rightarrow d)+p(c) p(c \rightarrow d)+p(d) p(d \rightarrow d)\\
&\quad= \medmath{\frac{1}{2}\cdot \frac{1}{12}+\frac{1}{8}\cdot \frac{1}{3}+\frac{1}{8\cdot } \frac{1}{3}}=\mfrac{1}{3}
\end{align*}
\end{fleqn}

\end{document} 

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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