1

I have a set of equations and I want to have them left-aligned instead of center-aligned. Also, I want them all to be numbered. I searched a bit and found that using flalign we can achieve this. But the results are not what I want. I want all the equations to start from the left at same position. What am I missing?

Here's the minimal working example showing what I have tried:

\documentclass{article}
\usepackage[fleqn]{amsmath}

\begin{document}
\begin{flalign}
  f_1 = \sigma(W_{1}x_1+W_{2}h_{1}+W_{3}c_{1}+b_1)  \\
  f_2 = \sigma(W_{2}x_2+b_2) \\
  c = f_i c+i\; \mathrm{cos}(W_{3}x_1+W_{3}h_{1}+b_3) \\
  y=c\; \mathrm{tanh}(f_1.f_2) 
\end{flalign}
\end{document}

enter image description here

  • 2
    This is surely related to the fact that you haven't actually specified an alignment point in your align environment. Also you should be using \cos for the proper spacing. Same with \tanh which, to my surprise, does seem to be provided out of the box. For those which aren't, like artanh, you'll wanna add \DeclareMathOperator{\artanh}{artanh} to the preamble and then use \artanh – Au101 Oct 3 '16 at 20:04
  • Do you want all your equations to be left-aligned, or only specific ones? – Bernard Oct 3 '16 at 20:20
  • @Bernard all of them. – CentAu Oct 3 '16 at 20:22
4

Under any of the align-like environments, each row follows a right-&-left alignment. As such, the first element in each row will necessarily be right-aligned, as you observed. If you want a left-alignment, consider adding "an empty first group" by just prepending each row by &.

Here are some options:

enter image description here

\documentclass{article}

\usepackage[fleqn]{amsmath}
\setlength{\mathindent}{0pt}

\begin{document}

\noindent X\dotfill X
\begin{flalign}
  & f_1 = \sigma(W_1 x_1 +W_2 h_1 + W_3 c_1 + b_1) \\
  & f_2 = \sigma(W_2 x_2 + b_2) \\
  &   c = f_i c + i \cos(W_3 x_1 + W_3 h_1 + b_3) \\
  &   y = c \tanh(f_1.f_2) 
\end{flalign}
\noindent X\dotfill X
\begin{flalign}
  f_1 &= \sigma(W_1 x_1 +W_2 h_1 + W_3 c_1 + b_1) \\
  f_2 &= \sigma(W_2 x_2 + b_2) \\
    c &= f_i c + i \cos(W_3 x_1 + W_3 h_1 + b_3) \\
    y &= c \tanh(f_1.f_2) 
\end{flalign}
\noindent X\dotfill X

\end{document}

You might be interested in the first representation. I prefer the second.

Note that there already exist operators for the math function you write in roman font: \cos and \tanh. If you wish to define additional ones (and therefore provide the appropriate spacing) use \operatorname and/or \DeclareMathOperator{<macro>}{<name>}. See What's the difference between \mathrm and \operatorname? and Define additional math operators to be typeset in roman.

  • Awesome! Thanks for the helpful explanations. – CentAu Oct 3 '16 at 20:47
1

Note the default for the [fleqn] option of amsmath uses a display indent (~ 2.5em?). The flalign environment, independently of the option, displays equations full line width and thus aligns them with the left margin.

Here are a few examples of the different possible situations:

\documentclass{article}
\usepackage[showframe]{geometry}%
 \usepackage[fleqn]{amsmath}%
 \usepackage{nccmath}

 \begin{document}

\begin{flalign}
  f_1 & = \sigma(W_{1}x_1+W_{2}h_{1}+W_{3}c_{1}+b_1 & \\
  f_2 & = \sigma(W_{2}x_2+b_2) \\
  c & = f_i c+i\; \cos(W_{3}x_1+W_{3}h_{1}+b_3) \\
  y & =c\; \tanh(f_1.f_2)
\end{flalign}
\bigskip

\begin{flalign}
 & \begin{gathered}
  f_1  = \sigma(W_{1}x_1+W_{2}h_{1}+W_{3}c_{1}+b_1  \\
  f_2  = \sigma(W_{2}x_2+b_2) \\
  c  = f_i c+i\; \cos(W_{3}x_1+W_{3}h_{1}+b_3) \\
  y  =c\; \tanh(f_1.f_2)
  \end{gathered} &
\end{flalign}
\bigskip

  \begin{align}
 f_1 & = \sigma(W_{1}x_1+W_{2}h_{1}+W_{3}c_{1}+b_1  \\
   f_2 & = \sigma(W_{2}x_2+b_2) \\
  c & = f_i c+i\; \cos(W_{3}x_1+W_{3}h_{1}+b_3) \\
  y & =c\; \tanh (f_1.f_2)
  \end{align}
\bigskip

 \begin{align} &  \begin{gathered}
 f_1  = \sigma(W_{1}x_1+W_{2}h_{1}+W_{3}c_{1}+b_1  \\
   f_2  = \sigma(W_{2}x_2+b_2) \\
  c  = f_i c+i\; \cos(W_{3}x_1+W_{3}h_{1}+b_3) \\
  y  =c\; \tanh (f_1.f_2)
  \end{gathered}
  \end{align}

\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.