长公式超出边距(无换行符)

长公式超出边距(无换行符)
\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} 

在此处输入图片描述

答案1

首先,您需要\allowdisplaybreaks在 17 行环境开始之前发出指令align。(不要使用equation,因为equation不允许换行。)

我还想建议你摆脱所有(是的,全部) 106\left和 106\right大小调整指令,因为它们没有任何用处,但确实会造成大量代码混乱。我还建议删除 (a) 较长术语周围的括号\frac(同样,它们是不必要的)和 (b) 大量花括号,它们同样没有任何用处,同时使代码几乎不可读。

接下来,我会\quad在每对输出行的第二行开头插入指令,并在每对输出行的末尾更改为\\\\[1.25ex]主要是为了提供一些急需的视觉分组。

然而,即使采取了所有这些建议,一旦编写完成,仍然几乎不可能真正维护此代码块。同样,很难检测到您提供的方程式实际上缺少 16 个必需项中的 1 个。此外,在一个表达式中,您写下了E_l^ma它应该在的位置E_l^{ma};这当然只是一个拼写错误,但您的方程式的重复结构使得发现和消除它们相当困难。而且,即使它“只是一个拼写错误”,它仍然会损害整体外观。

如果你能够使用 LuaLaTeX,我强烈建议你进行切换,因为它允许你创建方程式以编程方式,通过创建嵌套for循环。例如,如下所示:

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

以下是排版输出的前七行:

在此处输入图片描述


当然,如果文本块足够宽,可以通过删除-terms 前的换行符将 33 行方程更改为 17 行表达式\log_2

在此处输入图片描述

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

答案2

没有人喜欢阅读长篇大论的文字,而真正重要的细节却隐藏在众多符号之中,因此我提出了一种不同的解决方案。

%\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} 

这样公式的内部结构就更容易理解了。也许你可以为 想出一个更好的名字F

在此处输入图片描述

避免使用过多的圆括号和无用的括号。例如,周围的括号\log_2甚至是错误的。您可以看到,\left除了\right产生不必要的小空格外,它没有任何用处。请注意\mathit{MI},因为它似乎是一个唯一的函数标识符,而不是乘法。

答案3

环境中的长数学表达式equation不能分成多行。为此,您必须使用amsmath诸如、等环境align之一gather

由于我没有使用过文档类,所以我使用它book(希望它的默认大小\textwidth与大致相同CUIThesisV,看看以下建议是否适合您:

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

在此处输入图片描述

(红线表示文本边框)

如果\textwidth小于book,那么您可以\textwidth使用包\adjustwidth中定义的宏来局部改变这个方程changepage

相关内容