8

I need to place the following bulk of equation to left alignment with keeping the equation number in the middle, however using flalign require set option on/off by line for equation number which at last will not be in the middle.

 \begin{flalign}
    \ell_1(\bm{\phi})& =\sum_{i=1}^{N-N^*} \sum_{j=2}^{d_i-1} ln(1- 
    \bm{P}_{ij}),&\nonumber\\
    \ell_2(\bm{\phi})& =\sum_{i=1}^{N-N^*} ln\,\bm{P}_{id_i},&
 \end{flalign}

On the other hand, when using aligned with equation, equation number will be in the middle but the whole bulk of equation moved to center.

\begin{equation}
 \begin{aligned}
    \ell_1(\bm{\phi})& =\sum_{i=1}^{N-N^*} \sum_{j=2}^{d_i-1} ln(1- 
    \bm{P}_{ij}),\\
    \ell_2(\bm{\phi})& =\sum_{i=1}^{N-N^*} ln\,\bm{P}_{id_i},
 \end{aligned}
\end{equation}

How can I keep the equation left aligned with equation number in the middle.

7

It's not clear why a particular equation should be left aligned. If you want all equations to be left aligned, use the fleqn option.

Anyway, here's a way with flalign.

Function names such as “ln”, “sin”, “exp” should be typed in with a backslash: \ln and so on; this will give the correct spacing, besides using upright font shape.

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

\usepackage[nopar]{lipsum} % for context

\begin{document}

\lipsum[4]
\begin{flalign}
& \begin{aligned}
    \ell_1(\bm{\phi})& =\sum_{i=1}^{N-N^*} \sum_{j=2}^{d_i-1} \ln(1-\bm{P}_{ij}),\\
    \ell_2(\bm{\phi})& =\sum_{i=1}^{N-N^*} \ln\bm{P}_{id_i},
 \end{aligned}
&&
\end{flalign}
\lipsum[4]

\end{document}

enter image description here

  • I know that setting fleqn as option in the document class make all equation left alignment, however I just want them left alignment only in the proof appendix while all equation in all the thesis are in center alignment. However, I use your suggested solution by using flalign with aligned and it worked perfectly. – N. I. ElZayat Dec 18 '18 at 10:49
6

Do note that the left-hand shift of the first set of equations is not caused by the use of flalign, per se. Instead, the shift is caused by the presence of additional & symbols.

To shift a nested equation/aligned system to the left, all you need to do is insert the instruction

\hspace*{6cm}\null  % choose offset amount suitably

between \end{aligned} and \end{equation}.

Oh, and do please write \ln rather than just ln to denote the natural logarithm operator.

enter image description here

\documentclass{article}
\usepackage{amsmath,bm}
\begin{document}
\begin{equation}
\begin{aligned}
   \ell_1(\bm{\phi}) &= \sum_{i=1}^{N-N^*} \sum_{j=2}^{d_i-1} \ln(1-\bm{P}_{ij}),\\
   \ell_2(\bm{\phi}) &= \sum_{i=1}^{N-N^*} \ln\bm{P}_{id_i},
\end{aligned}\hspace*{6cm}\null  % choose offset amount suitably
\end{equation}
\end{document} 
  • 1
    You won for 35 seconds :-) Excellent and congratulations on your response. – Sebastiano Dec 18 '18 at 9:57
  • Your solution also work perfect with me – N. I. ElZayat Dec 18 '18 at 11:16
5

You can use the fleqn environment from nccmath, which makes equations in the environment start at a fixed distance of the left margin via an optional argument (default 0pt):

\documentclass{article}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.3pt}
\usepackage{amsmath, bm, nccmath}

\begin{document}

\begin{fleqn}[1em]
  \begin{equation}
 \begin{aligned}
    \ell_1(\bm{\phi})& =\sum_{i=1}^{N-N^*} \sum_{j=2}^{d_i-1} \ln(1-
    \bm{P}_{ij}),\\
    \ell_2(\bm{\phi})& =\sum_{i=1}^{N-N^*} \ln\,\bm{P}_{id_i},
 \end{aligned}
\end{equation}
\end{fleqn}

\end{document} 

enter image description here

  • 1
    Oh! yes. Actually I didn't what the O.P. had written. Thanks! – Bernard Dec 18 '18 at 10:10
3

You could, alternatively use, \usepackage{empheq}. Here I have added a picture of the differents environment (see the table) that you can use: enter image description here

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

enter image description here

\documentclass{article}
\usepackage{empheq}
\usepackage{amsmath}
\usepackage{bm}
\begin{document}

\begin{empheq}{flalign}
  \begin{aligned}
    \ell_1(\bm{\phi})& =\sum_{i=1}^{N-N^*} \sum_{j=2}^{d_i-1} \ln(1- 
    \bm{P}_{ij}),\\
    \ell_2(\bm{\phi})& =\sum_{i=1}^{N-N^*} \ln\,\bm{P}_{id_i},
  \end{aligned}&&
\end{empheq}


\end{document}
  • 1
    In fact this package does not work with me. The equation still appears in center alignment. – N. I. ElZayat Dec 18 '18 at 10:51
  • 1
    Your LaTeX distribution will probably not be updated. Try to check the date of your version. – Sebastiano Dec 18 '18 at 10:59
  • It seems that you'r right I will check for an update. – N. I. ElZayat Dec 18 '18 at 11:13
  • @ samcarter I did not update I used one solution of the suggested above and it works great with me – N. I. ElZayat Dec 18 '18 at 13:28

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.