2

What is the best way to write the following equation:

\begin{flalign} 
\begin{aligned}
 &\qquad\qquad\frac{\partial^2 \ell}{\partial \bm{\phi}\partial\bm{\phi}'}=\\
 &\sum_{i=1}^{N-N^*} \Bigg(\bigg[\sum_{j=2}^{d_i-1} -\;\tfrac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{id_i}'(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})}{(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})+\bm{P}_{id_i}'\bm{P}_{id_i}}
 \mathbf{\tilde{Y}}_{d_i} \mathbf{\tilde{Y}}'_{d_i}\bigg]\\
 &-\bigg[\sum_{j=2}^{d_i-1} \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
  \mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j+\tfrac{(1-\bm{P}_{id_i})}{\bm{P}'_{id_i}}
  \mathbf{\tilde{Y}}_{d_i} \bm{P}_{id_i}(1-\bm{P}_{id_i}) \mathbf{\tilde{Y}}'_{d_i} \bigg]\Bigg)\\
 &-\sum_{i=1}^{N^*} \sum_{j=2}^{n_i}\bigg[\tfrac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
  \mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j\bigg]
 \end{aligned}
 &&
 \end{flalign}

Following is an image to how it looks like in the way I wrote the code above

enter image description here

I tried also to use multiline but did not get a nice look either.

I change the code using footnotesize, the new code is

{\footnotesize
    \begin{flalign}  \label{18}
\begin{aligned}
 \frac{\partial^2 \ell}{\partial \bm{\phi}\partial\bm{\phi}'}&=\sum_{i=1}^{N-N^*} \Bigg(\bigg[\sum_{j=2}^{d_i-1} -\;\tfrac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{id_i}'(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})}{(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})+\bm{P}_{id_i}'\bm{P}_{id_i}}
 \mathbf{\tilde{Y}}_{d_i} \mathbf{\tilde{Y}}'_{d_i}\bigg]\\
 &\qquad-\bigg[\sum_{j=2}^{d_i-1} \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
  \mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j+\tfrac{(1-\bm{P}_{id_i})}{\bm{P}'_{id_i}}
  \mathbf{\tilde{Y}}_{d_i} \bm{P}_{id_i}(1-\bm{P}_{id_i}) \mathbf{\tilde{Y}}'_{d_i} \bigg]\Bigg)\\
 &\qquad-\sum_{i=1}^{N^*} \sum_{j=2}^{n_i}\bigg[\tfrac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
  \mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j\bigg]
 \end{aligned}
 &&
 \end{flalign}
}

It looks now as: enter image description here

  • 2
    Please do not post code snippets - create minimal working examples (MWEs) instead. – epR8GaYuh Dec 18 '18 at 13:29
  • I post it as it is because the equation is splitted in many line. I can't compile the above code here to show how it is very messy – N. I. ElZayat Dec 18 '18 at 13:33
  • 1
    Please state, in words, what you would like to achieve. Please also state what the main font size is and how wide the text block is. – Mico Dec 18 '18 at 13:37
  • 1
    Do you use the default layout (with a very large outer margin) or do you customise your layout (say with geometry)? – Bernard Dec 18 '18 at 13:54
  • 2
    The combination of \footnotesize and \tfrac makes reading the material quite a chore -- unless a free magnifying glass is handed out... – Mico Dec 18 '18 at 15:06
8

Do six lines. I changed the position of some of the brackets from before to after the summation sign and reduced the size.

Note that it should be \bigl for a left delimiter and \bigr for a right one (with the obvious variations for Big, bigg and Bigg).

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

\begin{document}

\begin{flalign}
\begin{aligned}
\frac{\partial^2 \ell}{\partial \bm{\phi}\,\partial\bm{\phi}'}={}&
   \begin{aligned}[t]
   \sum_{i=1}^{N-N^*}
   \biggl(\,\sum_{j=2}^{d_i-1}\Bigl[
     & -\frac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}
              {(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}
        \tilde{\mathbf{Y}}_j \tilde{\mathbf{Y}}'_j
     \\
     & +\frac{\bm{P}_{id_i}'(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})}
             {(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})+\bm{P}_{id_i}'\bm{P}_{id_i}}
       \tilde{\mathbf{Y}}_{d_i} \tilde{\mathbf{Y}}'_{d_i}\Bigr]
  \\
    -\sum_{j=2}^{d_i-1}\Bigl[
     & \frac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
       \tilde{\mathbf{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \tilde{\mathbf{Y}}'_j
     \\
     &  +\frac{(1-\bm{P}_{id_i})}{\bm{P}'_{id_i}}
         \tilde{\mathbf{Y}}_{d_i} \bm{P}_{id_i}(1-\bm{P}_{id_i}) \tilde{\mathbf{Y}}'_{d_i} \Bigr]\biggr)
   \end{aligned}
\\
 &\begin{aligned}[t]
    -\sum_{i=1}^{N^*} \sum_{j=2}^{n_i}\Bigl[
    & \frac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}
            {(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}
      \tilde{\mathbf{Y}}_j \tilde{\mathbf{Y}}'_j
    \\
    & + \frac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
        \tilde{\mathbf{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \tilde{\mathbf{Y}}'_j\Bigr]
  \end{aligned}
\end{aligned}
&&
\end{flalign}

\end{document}

enter image description here

I changed all \mathbf{\tilde{Y}} to \tilde{\mathbf{Y}} that's conceptually sounder. You may also want to use \widetilde, but I don't recommend so.

  • 2
    I'd be tempted to replace all instances of \mathbf{\tilde{Y}} with \widetilde{\mathbf{Y}}. – Mico Dec 18 '18 at 14:14
  • 3
    @Mico It should be \tilde{\mathbf{Y}}, much likely. – egreg Dec 18 '18 at 14:16
  • Nice touch to supply the missing inner brackets, by the way. – Mico Dec 18 '18 at 14:18
  • @egreg it is really looks very nice – N. I. ElZayat Dec 18 '18 at 14:32
3

Reduce the text size or make it spread into several lines.

\begin{flalign}
{\footnotesize 
\begin{aligned}
\frac{\partial^2 \ell}{\partial \bm{\phi}\partial\bm{\phi}'}=
&\sum_{i=1}^{N-N^*} \Bigg(\bigg[\sum_{j=2}^{d_i-1} -\;\tfrac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{id_i}'(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})}{(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})+\bm{P}_{id_i}'\bm{P}_{id_i}}\\&
\mathbf{\tilde{Y}}_{d_i} \mathbf{\tilde{Y}}'_{d_i}\bigg]
-\bigg[\sum_{j=2}^{d_i-1} \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
\mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j+\tfrac{(1-\bm{P}_{id_i})}{\bm{P}'_{id_i}}
\mathbf{\tilde{Y}}_{d_i} \bm{P}_{id_i}(1-\bm{P}_{id_i}) \mathbf{\tilde{Y}}'_{d_i} \bigg]\Bigg)\\
&-\sum_{i=1}^{N^*} \sum_{j=2}^{n_i}\bigg[\tfrac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
\mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j\bigg]
\end{aligned}}
\end{flalign}
  • 1
    I just notice your answer, this is exactly what comes to my mind before I saw you answer – N. I. ElZayat Dec 18 '18 at 14:06
  • 1
    And you remembered to check the log before you posted this? Hint: \footnotesize is not allowed in math mode. – daleif Dec 18 '18 at 14:08
  • 3
    No error is not the same as not being correct. You get LaTeX Font Warning: Command \footnotesize invalid in math mode if you look in the log. Never use text font resizing commands in math mode. – daleif Dec 18 '18 at 14:16
  • 2
    It is still a bad practise that should be avoided in a good document design. – daleif Dec 18 '18 at 14:47
  • 2
    Shrinking the font to make something fit is a bad idea regardless. – JPi Dec 18 '18 at 17:04
3

enter image description here

I've made the code a bit more legible and changed \Bigg( to \Biggl( etc. Also, I'm using the multline environment from amsmath which is suitable here.

\documentclass{article}

\usepackage{amsmath}
\usepackage{bm}
\usepackage[margin=1in]{geometry}

\newcommand{\bP}{\bm{P}}
\newcommand{\tY}{\mathbf{\tilde Y}}
\begin{document}
\begin{multline} 
\frac{\partial^2 \ell}{\partial \bm{\phi}\partial\bm{\phi}'}=
 \sum_{i=1}^{N-N^*} \Biggl(\biggl[\sum_{j=2}^{d_i-1} -\;\frac{\bP_{ij}'\bP_{ij} (1-\bP_{ij})'}{(1-\bP_{ij})'(1-\bP_{ij})+\bP_{ij}'\bP_{ij}}\tY_j \tY'_j + \frac{\bP_{id_i}'(1-\bP_{id_i})'(1-\bP_{id_i})}{(1-\bP_{id_i})'(1-\bP_{id_i})+\bP_{id_i}'\bP_{id_i}}
 \tY_{d_i} \tY'_{d_i}\biggr]\\
 -\biggl[\sum_{j=2}^{d_i-1} \frac{\bP_{ij}}{(1-\bP_{ij})'}
  \tY_j \bP_{ij}(1-\bP_{ij}) \tY'_j+\frac{(1-\bP_{id_i})}{\bP'_{id_i}}
  \tY_{d_i} \bP_{id_i}(1-\bP_{id_i}) \tY'_{d_i} \biggr]\Biggr)\\
 -\sum_{i=1}^{N^*} \sum_{j=2}^{n_i}\biggl[\frac{\bP_{ij}'\bP_{ij} (1-\bP_{ij})'}{(1-\bP_{ij})'(1-\bP_{ij})+\bP_{ij}'\bP_{ij}}\tY_j \tY'_j + \frac{\bP_{ij}}{(1-\bP_{ij})'}
  \tY_j \bP_{ij}(1-\bP_{ij}) \tY'_j\biggr]
\end{multline}

\end{document}
2

I propose this, with package geometry. If you have the default layout with large margins, you can nest the equation contents in a medsize environment from nccmath (~ 80% of previous size):

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

 \begin{document}

 \begin{equation}
\begin{aligned}\diffp[1,1]{\ell}{\bm{\phi},\bm{\phi}'} =
 \sum_{i=1}^{N-N^*} \Bigg( & \bigg[\begin{aligned}[t]\sum_{j=2}^{d_i-1} -\;\tfrac{\bm{P}_{ij}'
\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{id_i}'(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})}{(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})+\bm{P}_{id_i}'\bm{P}_{id_i}}
 \mathbf{\tilde{Y}}_{d_i} \mathbf{\tilde{Y}}'_{d_i} & \bigg]\\
 %&
 - \bigg[\sum_{j=2}^{d_i-1} \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
  \mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j+\tfrac{(1-\bm{P}_{id_i})}{\bm{P}'_{id_i}}
  \mathbf{\tilde{Y}}_{d_i} \bm{P}_{id_i}(1-\bm{P}_{id_i}) \mathbf{\tilde{Y}}'_{d_i} &\bigg]\Bigg)
  \end{aligned}\\
% &
-\sum_{i=1}^{N^*} \sum_{j=2}^{n_i} & \bigg[\tfrac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
  \mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j\bigg]
\end{aligned}
 \end{equation}
 \bigskip

 \begin{equation}
\begin{medsize}
\begin{aligned}\diffp[1,1]{\ell}{\bm{\phi},\bm{\phi}'} =
 \sum_{i=1}^{N-N^*} \Biggl( & \Biggl[\begin{aligned}[t]\sum_{j=2}^{d_i-1} -\;\tfrac{\bm{P}_{ij}'
\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{id_i}'(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})}{(1-\bm{P}_{id_i})'(1-\bm{P}_{id_i})+\bm{P}_{id_i}'\bm{P}_{id_i}}
 \mathbf{\tilde{Y}}_{d_i} \mathbf{\tilde{Y}}'_{d_i} & \Biggr]\\
 %&
 - \Biggl[\sum_{j=2}^{d_i-1} \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
  \mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j+\tfrac{(1-\bm{P}_{id_i})}{\bm{P}'_{id_i}}
  \mathbf{\tilde{Y}}_{d_i} \bm{P}_{id_i}(1-\bm{P}_{id_i}) \mathbf{\tilde{Y}}'_{d_i} &\Biggr]\Biggr)
  \end{aligned}\\
% &
-\sum_{i=1}^{N^*} \sum_{j=2}^{n_i} & \biggl[\tfrac{\bm{P}_{ij}'\bm{P}_{ij} (1-\bm{P}_{ij})'}{(1-\bm{P}_{ij})'(1-\bm{P}_{ij})+\bm{P}_{ij}'\bm{P}_{ij}}\mathbf{\tilde{Y}}_j \mathbf{\tilde{Y}}'_j + \tfrac{\bm{P}_{ij}}{(1-\bm{P}_{ij})'}
  \mathbf{\tilde{Y}}_j \bm{P}_{ij}(1-\bm{P}_{ij}) \mathbf{\tilde{Y}}'_j\biggr]
\end{aligned}
\end{medsize}
 \end{equation}

\end{document}

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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