0
\documentclass[12pt, a4paper, oneside]{CUIThesisV}
\usepackage{placeins}
\usepackage{multirow}
\usepackage{mathrsfs}
\usepackage{amssymb,amsthm}
\begin{document}

\begin{equation}\label{C2eq61}
\tiny
%\begin{align}\label{C2eq61}
%\MoveEqLeft
MI\left( {{E_i},{E_j},E_k^a,E_l^{ma}} \right) = \nonumber \\
& p\left( {{E_i} = 0,E_j = 0,E_k^a = 0,E_l^{ma} = 0} \right)\nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 0,E_j = 0,E_k^a = 0,E_l^{ma} = 0} \right)}}{{p\left( {{E_i} = 0} \right)p\left( {E_j = 0} \right)p\left( {E_k^a = 0} \right)p\left( {E_l^{ma} = 0} \right)}}} \right)\nonumber \\
& + p\left( {{E_i} = 0,E_j = 0,E_k^a = 0,E_l^{ma} = 1} \right)\nonumber\\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 0,E_j = 0,E_k^a = 0,E_l^{ma} = 1} \right)}}{{p\left( {{E_i} = 0} \right)p\left( {E_j = 0} \right)p\left( {E_k^a = 0} \right)p\left( {E_l^{ma} = 1} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 0,E_j = 0,E_k^a = 1,E_l^{ma} = 0} \right)\nonumber\\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 0,E_j = 0,E_k^a = 1,E_l^{ma}= 0} \right)}}{{p\left( {{E_i} = 0} \right)p\left( {E_j = 0} \right)p\left( {E_k^a = 1} \right)p\left( {E_l^{ma} = 0} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 0,E_j = 0,E_k^a = 1,E_l^{ma} = 1} \right)\nonumber\\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 0,E_j = 0,E_k^a = 1,E_l^{ma} = 1} \right)}}{{p\left( {{E_i} = 0} \right)p\left( {E_j = 0} \right)p\left( {E_k^a = 1} \right)p\left( {E_l^{ma} = 1} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 0,E_j = 1,E_k^a = 0,E_l^{ma} = 0} \right) \nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 0,E_j = 1,E_k^a = 0,E_l^{ma} = 0} \right)}}{{p\left( {{E_i} = 0} \right)p\left( {E_j = 1} \right)p\left( {E_k^a = 0} \right)p\left( {E_l^{ma} = 0} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 0,E_j = 1,E_k^a = 0,E_l^{ma} = 1} \right) \nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 0,E_j = 1,E_k^a = 0,E_l^{ma} = 1} \right)}}{{p\left( {{E_i} = 0} \right)p\left( {E_j = 1} \right)p\left( {E_k^a = 0} \right)p\left( {E_l^{ma} = 1} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 0,E_j = 1,E_k^a = 1,E_l^{ma} = 0} \right)\nonumber\\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 0,E_j = 1,E_k^a = 1,E_l^{ma} = 0} \right)}}{{p\left( {{E_i} = 0} \right)p\left( {E_j = 1} \right)p\left( {E_k^a = 1} \right)p\left( {E_l^{ma} = 0} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 0,E_j = 1,E_k^a = 1,E_l^{ma} = 1} \right)\nonumber\\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 0,E_j = 1,E_k^a = 1,E_l^{ma} = 1} \right)}}{{p\left( {{E_i} = 0} \right)p\left( {E_j = 1} \right)p\left( {E_k^a = 1} \right)p\left( {E_l^{ma} = 1} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 1,E_j = 0,E_k^a = 0,E_l^{ma} = 0} \right) \nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 1,E_j = 0,E_k^a = 0,E_l^{ma} = 0} \right)}}{{p\left( {{E_i} = 1} \right)p\left( {E_j = 0} \right)p\left( {E_k^a = 0} \right)p\left( {E_l^{ma} = 0} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 1,E_j = 0,E_k^a = 0,E_l^ma = 1} \right) \nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 1,E_j = 0,E_k^a = 0,E_l^{ma} = 1} \right)}}{{p\left( {{E_i} = 1} \right)p\left( {E_j = 0} \right)p\left( {E_k^a = 0} \right)p\left( {E_l^{ma} = 1} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 1,E_j = 0,E_k^a = 1,E_l^{ma} = 1} \right)\nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 1,E_j = 0,E_k^a = 1,E_l^{ma} = 1} \right)}}{{p\left( {{E_i} = 1} \right)p\left( {E_j = 0} \right)p\left( {E_k^a = 1} \right)p\left( {E_l^{ma} = 1} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 1,E_j = 1,E_k^a = 0,E_l^{ma} = 0} \right) \nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 1,E_j = 1,E_k^a = 0,E_l^{ma} = 0} \right)}}{{p\left( {{E_i} = 1} \right)p\left( {E_j = 1} \right)p\left( {E_k^a = 0} \right)p\left( {E_l^{ma} = 0} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 1,E_j = 1,E_k^a = 0,E_l^{ma}= 1} \right) \nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 1,E_j = 1,E_k^a = 0,E_l^{ma} = 1} \right)}}{{p\left( {{E_i} = 1} \right)p\left( {E_j = 1} \right)p\left( {E_k^a = 0} \right)p\left( {E_l^{ma} = 1} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 1,E_j^t = 1,E_k^a = 1,E_l^{ma} = 0} \right) \nonumber \\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 1,E_j = 1,E_k^a = 1,E_l^{ma} = 0} \right)}}{{p\left( {{E_i} = 1} \right)p\left( {E_j = 1} \right)p\left( {E_k^n = 1} \right)p\left( {E_l^m = 0} \right)}}} \right) \nonumber \\
& + p\left( {{E_i} = 1,E_j = 1,E_k^a = 1,E_l^{ma} = 1} \right) \nonumber\\
& \times {\log _2}\left( {\frac{{p\left( {{E_i} = 1,E_j = 1,E_k^a = 1,E_l^{ma} = 1} \right)}}{{p\left( {{E_i} = 1} \right)p\left( {E_j = 1} \right)p\left( {E_k^a = 1} \right)p\left( {E_l^{ma} = 1} \right)}}} \right)
%\end{align}
\end{equation}

\end{document} 

enter image description here

3
  • 2
    Are the files of the CUIThesisV document class available online?
    – Mico
    Feb 28, 2021 at 7:42
  • Incidentally, the equation should contain 16 separate terms on the right-hand side, but it currently contains only 15.
    – Mico
    Feb 28, 2021 at 10:28
  • I really think that your equation is badly designed. You should introduce some notations such as to simplify its reading.
    – projetmbc
    Feb 28, 2021 at 11:03

3 Answers 3

3

First and foremost, you need to issue an \allowdisplaybreaks directive before the start of the 17-line align environment. (Don't use equation, since equation doesn't allow line breaks to begin with.)

I would further like to recommend that you get rid of all (yes, all) 106 \left and 106 \right sizing directives, as they contribute nothing useful, but do create a lot of code clutter. I would also recommend getting rid of (a) the parentheses around the long-ish \frac terms -- again, they're not needed -- and (b) the multitude of curly braces that, once again, do nothing useful, while rendering the code nearly unreadable.

Next, I'd insert \quad directives at the start of the second of each pair of output lines, and I'd change \\ to \\[1.25ex] at the end of each such pair, mainly to provide some much-needed visual grouping.

However, even with all of these recommendations in place, it's still well-nigh impossible to truly maintain this code chunk once it's written. It's also not straightforward to detect that the equation, as provided by you, is actually missing 1 of the 16 required terms. Moreover, in one expression you wrote E_l^ma where it really ought to be E_l^{ma}; that's of course nothing but a typo, but the repetitive structure of your equations makes it rather difficult to spot and eradicate them. And, even though it's "just a typo", it still detracts from the overall appearance.

If you're at all able to use LuaLaTeX, I'd strongly recommend that you make the switch, as it allows you to create the equation programmatically, by creating for nested for loops. I.e., something like this:

\documentclass[12pt, a4paper, oneside]{book} % {CUIThesisV}

\usepackage{amsmath}
\allowdisplaybreaks
\directlua{ % define a Lua function that prints 4^2=16 lines
function Print16Lines ( label ) % argument of function is equation's label
  line=1
  for i=0,1 do
    for j=0,1 do
      for k=0,1 do
        for l=0,1 do          
          if line==1 then
             tex.sprint ( "&\\phantom{{}+{}}" )
          else
             tex.sprint ( "&+" )
          end
          tex.sprint ( "p(E_i=" ..i.. ",E_j=" ..j.. ",E_k^a=" .. k.. ",E_l^{ma}=" ..l.. ") \\notag \\\\*" ) % "*" forbids page break
          tex.sprint ( "&\\qquad\\times \\log_2 \\frac{p(E_i=" ..i.. ",E_j=" ..j.. ",E_k^a=" ..k.. ",E_l^{ma}=" ..l.. ")}") % numerator
          tex.sprint ( "{p(E_i=" ..i.. ")\\,p(E_j=" ..j.. ")\\,p(E_k^a=" ..k.. ")\\,p(E_l^{ma}=" ..l.. ")}" ) % denominator
          if line<16 then 
             tex.sprint ( "\\notag  \\\\[1.25ex]" )
          else 
             tex.sprint ( "\\label{" ..label .."}" ) % last line
          end
          line=line+1
        end
      end
    end
  end
end
}
\begin{document}
\begin{align}
  \mathit{MI} &( E_i, E_j, E_k^a, E_l^{ma} ) = \notag  \\[1.25ex] 
  \directlua{Print16Lines("C2eq61")}
\end{align}
\end{document}

Here are the first seven lines of the typeset output:

enter image description here


Of course, if the text block is sufficiently wide, it's possible to change the 33-line equation to a 17-line expression by getting rid of the line breaks before the \log_2-terms.

enter image description here

\documentclass[12pt, a4paper, oneside]{book} % {CUIThesisV}
\usepackage[margin=2.5cm]{geometry} % set page parameters suitably

\usepackage{amsmath} % for 'align' env. and '\allowdisplaybreaks' macro
\allowdisplaybreaks   
\directlua{ % define a Lua function that prints 4^2=16 lines
function Print16Lines ( ) 
  line=1
  for i=0,1 do
    for j=0,1 do
      for k=0,1 do
        for l=0,1 do          
          if line==1 then
             tex.sprint ( "&\\phantom{{}+{}}" ) % if on first line
          else
             tex.sprint ( "&+" )
          end
          tex.sprint ( "p(E_i=" ..i.. ",E_j=" ..j.. ",E_k^a=" .. k.. ",E_l^{ma}=" ..l.. ")\\times\\log_2" ) 
          tex.sprint ( "\\frac{p(E_i=" ..i.. ",E_j=" ..j.. ",E_k^a=" ..k.. ",E_l^{ma}=" ..l.. ")}") % numerator
          tex.sprint ( "{p(E_i=" ..i.. ")\\,p(E_j=" ..j.. ")\\,p(E_k^a=" ..k.. ")\\,p(E_l^{ma}=" ..l.. ")}" ) % denom.
          if line<16 then 
             tex.sprint ( "\\notag \\\\[0.75ex]" ) 
          end
          line=line+1
        end
      end
    end
  end
end
}
 
\begin{document}

\begingroup % localize scope of the next two instructions
\medmuskip=2mu   % reduce whitespace around '+' and 'times"
\thickmuskip=2mu % reduce whitespace around ="
\begin{align} 
  \mathit{MI} &( E_i, E_j, E_k^a, E_l^{ma} ) = \notag \\ 
  \directlua{ Print16Lines() }
\end{align} \label{C2eq61}
\endgroup

\end{document}
6

Nobody likes to read a wall of text where the really important details are hidden among so many symbols, so I propose a different solution.

%\documentclass[12pt, a4paper, oneside]{CUIThesisV}
\documentclass[12pt, a4paper, oneside]{book}
\usepackage{amsmath,amssymb,amsthm}

\begin{document}

\begin{equation}
\label{C2eq61}
\mathit{MI}(E_i,E_j,E_k^a,E_l^{ma})=
\sum_{\substack{b_1\in\{0,1\} \\ b_2\in\{0,1\} \\ b_3\in\{0,1\} \\ b_4\in\{0,1\}}}
  F(b_1,b_2,b_3,b_4)
\end{equation}
where
\begin{equation*}
\begin{aligned}
F(b_1,b_2,b_3,b_4)&=
  p(E_i=b_1,E_j=b_2,E_k^a=b_3,E_l^{ma}=b_4) \\[1ex]
  &\quad\times
  \log_2\frac{p(E_i=b_1,E_j=b_2,E_k^a=b_3,E_l^{ma}=b_4)}
             {p(E_i=b_1)\,p(E_j=b_2)\,p(E_k^a=b_3)\,p(E_l^{ma}=b_4)}
\end{aligned}
\end{equation*}

\end{document} 

This way the inner structure of the formula can be perceived more easily. Maybe you can devise a better name for F.

enter image description here

Avoid too many parentheses and useless braces. For instance the braces around \log_2 are even wrong. You can see that \left and \right do nothing useful except producing unwanted small spaces. Note \mathit{MI}, because it seems a unique function identifier, as opposed to a multiplication.

2
  • +1. The expression E_l^ma should be written as E_l^{ma}, though.
    – Mico
    Feb 28, 2021 at 11:38
  • @Mico Thanks! I forgot that one!
    – egreg
    Feb 28, 2021 at 11:39
4

Long math expression in the equation environment cannot be broken into multi lines. For this you had to use one of amsmath environments as are align, gather, etc.

Since i haven't used document class, instead of it I use book (in hope that it default size of the \textwidth is approximately the same as at CUIThesisV, see if the following suggestion works for you:

\documentclass[12pt, a4paper, oneside]{book}%{CUIThesisV}
\usepackage{placeins}
\usepackage{multirow}
\usepackage{mathrsfs}
\usepackage{nccmath,    % added
            amssymb,amsthm, 
            mathtools}  % added
\allowdisplaybreaks
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

%\begin{equation}\label{C2eq61}
\footnotesize
\begin{fleqn}
\begin{align}\label{C2eq61}
\MoveEqLeft[0.35]
MI\left( {{E_i},{E_j},E_k^a,E_l^{ma}} \right) = \nonumber \\
    & p\left( {{E_i} = 0,E_j{=}0,E_k^a{=}0,E_l^{ma}{=}0} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}0,E_j{=}0,E_k^a{=}0,E_l^{ma}{=}0} \right)}}{{p\left( {{E_i}{=}0} \right)p\left( {E_j{=}0} \right)p\left( {E_k^a{=}0} \right)p\left( {E_l^{ma}{=}0} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}0,E_j{=}0,E_k^a{=}0,E_l^{ma}{=}1} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}0,E_j{=}0,E_k^a{=}0,E_l^{ma}{=}1} \right)}}{{p\left( {{E_i}{=}0} \right)p\left( {E_j{=}0} \right)p\left( {E_k^a{=}0} \right)p\left( {E_l^{ma}{=}1} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}0,E_j{=}0,E_k^a{=}1,E_l^{ma}{=}0} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}0,E_j{=}0,E_k^a{=}1,E_l^{ma}= 0} \right)}}{{p\left( {{E_i}{=}0} \right)p\left( {E_j{=}0} \right)p\left( {E_k^a{=}1} \right)p\left( {E_l^{ma}{=}0} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}0,E_j{=}0,E_k^a{=}1,E_l^{ma}{=}1} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}0,E_j{=}0,E_k^a{=}1,E_l^{ma}{=}1} \right)}}{{p\left( {{E_i}{=}0} \right)p\left( {E_j{=}0} \right)p\left( {E_k^a{=}1} \right)p\left( {E_l^{ma}{=}1} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}0,E_j{=}1,E_k^a{=}0,E_l^{ma}{=}0} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}0,E_j{=}1,E_k^a{=}0,E_l^{ma}{=}0} \right)}}{{p\left( {{E_i}{=}0} \right)p\left( {E_j{=}1} \right)p\left( {E_k^a{=}0} \right)p\left( {E_l^{ma}{=}0} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}0,E_j{=}1,E_k^a{=}0,E_l^{ma}{=}1} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}0,E_j{=}1,E_k^a{=}0,E_l^{ma}{=}1} \right)}}{{p\left( {{E_i}{=}0} \right)p\left( {E_j{=}1} \right)p\left( {E_k^a{=}0} \right)p\left( {E_l^{ma}{=}1} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}0,E_j{=}1,E_k^a{=}1,E_l^{ma}{=}0} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}0,E_j{=}1,E_k^a{=}1,E_l^{ma}{=}0} \right)}}{{p\left( {{E_i}{=}0} \right)p\left( {E_j{=}1} \right)p\left( {E_k^a{=}1} \right)p\left( {E_l^{ma}{=}0} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}0,E_j{=}1,E_k^a{=}1,E_l^{ma}{=}1} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}0,E_j{=}1,E_k^a{=}1,E_l^{ma}{=}1} \right)}}{{p\left( {{E_i}{=}0} \right)p\left( {E_j{=}1} \right)p\left( {E_k^a{=}1} \right)p\left( {E_l^{ma}{=}1} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}1,E_j{=}0,E_k^a{=}0,E_l^{ma}{=}0} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}1,E_j{=}0,E_k^a{=}0,E_l^{ma}{=}0} \right)}}{{p\left( {{E_i}{=}1} \right)p\left( {E_j{=}0} \right)p\left( {E_k^a{=}0} \right)p\left( {E_l^{ma}{=}0} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}1,E_j{=}0,E_k^a{=}0,E_l^ma{=}1} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}1,E_j{=}0,E_k^a{=}0,E_l^{ma}{=}1} \right)}}{{p\left( {{E_i}{=}1} \right)p\left( {E_j{=}0} \right)p\left( {E_k^a{=}0} \right)p\left( {E_l^{ma}{=}1} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}1,E_j{=}0,E_k^a{=}1,E_l^{ma}{=}1} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}1,E_j{=}0,E_k^a{=}1,E_l^{ma}{=}1} \right)}}{{p\left( {{E_i}{=}1} \right)p\left( {E_j{=}0} \right)p\left( {E_k^a{=}1} \right)p\left( {E_l^{ma}{=}1} \right)}}} \right)       \notag  \\
& + p\left( {{E_i}{=}1,E_j{=}1,E_k^a{=}0,E_l^{ma}{=}0} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}1,E_j{=}1,E_k^a{=}0,E_l^{ma}{=}0} \right)}}{{p\left( {{E_i}{=}1} \right)p\left( {E_j{=}1} \right)p\left( {E_k^a{=}0} \right)p\left( {E_l^{ma}{=}0} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}1,E_j{=}1,E_k^a{=}0,E_l^{ma}{=}1} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}1,E_j{=}1,E_k^a{=}0,E_l^{ma}{=}1} \right)}}{{p\left( {{E_i}{=}1} \right)p\left( {E_j{=}1} \right)p\left( {E_k^a{=}0} \right)p\left( {E_l^{ma}{=}1} \right)}}} \right)       \notag  \\
    & + p\left( {{E_i}{=}1,E_j^t{=}1,E_k^a{=}1,E_l^{ma}{=}0} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}1,E_j{=}1,E_k^a{=}1,E_l^{ma}{=}0} \right)}}{{p\left( {{E_i}{=}1} \right)p\left( {E_j{=}1} \right)p\left( {E_k^n{=}1} \right)p\left( {E_l^m{=}0} \right)}}} \right)          \notag  \\
    & + p\left( {{E_i}{=}1,E_j{=}1,E_k^a{=}1,E_l^{ma}{=}1} \right)
\times {\log _2}\left( {\frac{{p\left( {{E_i}{=}1,E_j{=}1,E_k^a{=}1,E_l^{ma}{=}1} \right)}}{{p\left( {{E_i}{=}1} \right)p\left( {E_j{=}1} \right)p\left( {E_k^a{=}1} \right)p\left( {E_l^{ma}{=}1} \right)}}} \right)
\end{align}
\end{fleqn}

\end{document}

enter image description here

(redlines indicate text borders)

If \textwidth is smaller as at book, than you can for this equation can locally change \textwidth by use \adjustwidth macro defined in the changepage package.

2
  • 1
    I think the large parentheses aroudn the \frac terms aren't needed, either for the mathematics for typographic aesthetics.
    – Mico
    Feb 28, 2021 at 9:09
  • 1
    @Mico, you are right. I wouldn't use them and consequently increase \MoveEqLeft to 1. But I didn't took liberty to remove them.
    – Zarko
    Feb 28, 2021 at 9:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .