如何在 Latex 中拆分长分母的长方程式

如何在 Latex 中拆分长分母的长方程式

我是 Latex 的新手,我正在尝试写出下面的公式,但是我遇到了一些错误,我找不到它们。 在此处输入图片描述

 \documentclass{article}  
    \usepackage{amsmath}
    \begin{document}
    \begin{equation}
    \begin{split}
    E_q_2(A,B)
    &=\frac{1}{3n}\sum_{i=1}^{n}\frac{(1-e^{{-\mu}_A(x_i)})\times(1-e^{-\mu_B(x_i)})}{{(1-e^{{-\mu}_A(x_i)})}^2+{(1-e^{-\mu_B(x_i)})}^2-[(1-e^{{-\mu}_A(x_i)})\times(1-e^{-\mu_B(x_i)})]}\\
    &+ \frac{(1-e^{-(1-v_A(x_i))})\times(1-e^{-(1-v_B(x_i))})}{{(1-e^{-(1-v_A(x_i))})}^2+{(1-e^{-(1-v_B(x_i))})}^2-[(1-e^{-(1-v_A(x_i))})\times(1-e^{-(1-v_B(x_i))})]}\\
    &+\frac{(1-e^{-\frac{1}{2}(1+\mu_A(x_i)-v_A(x_i))})\times(1-e^{-\frac{1}{2}(1+\mu_B(x_i)-v_B(x_i))})}{
    \splitfrac{{(1-e^{-\frac{1}{2}(1+\mu_A(x_i)-v_A(x_i))})}^2+{(1-e^{-\frac{1}{2}(1+\mu_B(x_i)-v_B(x_i))})}^2 -}\\
     &{[(1-e^{-\frac{1}{2}(1+\mu_A(x_i)-v_A(x_i))})\times(1-e^{-\frac{1}{2}(1+\mu_B(x_i)-v_B(x_i))})]}}
    \end{split}
    \end{equation}
    \end{document}

由@koleygr 编辑:(按下标顺序但\splitfrac也被删除)

修正后的 MWE:

\documentclass{article}  
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{split}
E_{q_2}(A,B)
&=\frac{1}{3n}\sum_{i=1}^{n}\frac{(1-e^{{-\mu}_{A}(x_i)})\times(1-e^{-\mu_{B}(x_i)})}{{(1-e^{{-\mu}_{A}(x_i)})}^2+{(1-e^{-\mu_{B}(x_i)})}^2-[(1-e^{{-\mu}_{A}(x_i)})\times(1-e^{-\mu_{B}(x_i)})]}\\
&+ \frac{(1-e^{-(1-v_{A}(x_i))})\times(1-e^{-(1-v_{B}(x_i))})}{{(1-e^{-(1-v_{A}(x_i))})}^2+{(1-e^{-(1-v_{B}(x_i))})}^2-[(1-e^{-(1-v_{A}(x_i))})\times(1-e^{-(1-v_{B}(x_i))})]}\\
&+\frac{(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))})\times(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))})}{
{(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))})}^2+{(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))})}^2 -[(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))})\times(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))})]}
\end{split}
\end{equation}
\end{document}

答案1

如果由我来写的话,我会使用类似

演示

\documentclass{article}  
\usepackage{mathtools}
\begin{document}
\begin{equation}
E_{q_2}(A,B) = \frac{1}{3n}\sum_{i=1}^{n} \left( \frac{P_1(x_i)}{Q_1(x_i)}
    + \frac{P_2(x_i)}{Q_2(x_i)} + \frac{P_3(x_i)}{Q_3(x_i)} \right)
\end{equation}
where 
\addtocounter{equation}{-1}%
\begin{subequations}
\begin{align}
P_1(x_i) &= \left(1-e^{{-\mu}_{A}(x_i)}\right)\left(1-e^{-\mu_{B}(x_i)}\right)\\
Q_1(x_i) &= \left(1-e^{{-\mu}_{A}(x_i)}\right)^2+\left(1-e^{-\mu_{B}(x_i)}\right)^2 \notag\\
  &\quad - \left(1-e^{{-\mu}_{A}(x_i)}\right)\left(1-e^{-\mu_{B}(x_i)}\right)\\
P_2(x_i) &= \left(1-e^{-(1-v_{A}(x_i))}\right)\left(1-e^{-(1-v_{B}(x_i))}\right)\\
Q_2(x_i) &= \left(1-e^{-(1-v_{A}(x_i))}\right)^2+\left(1-e^{-(1-v_{B}(x_i))}\right)^2 \notag\\
  &\quad - \left(1-e^{-(1-v_{A}(x_i))}\right)\left(1-e^{-(1-v_{B}(x_i))}\right)\\
P_3(x_i) &= \left(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))}\right)
    \left(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))}\right)\\
\shortintertext{and}
Q_3(x_i) &= \left(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))}\right)^2
    +\left(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))}\right)^2 \notag\\
  &\quad - \left(1-e^{-\frac{1}{2}(1+\mu_{A}(x_i)-v_{A}(x_i))}\right)
    \left(1-e^{-\frac{1}{2}(1+\mu_{B}(x_i)-v_{B}(x_i))}\right)
\end{align}
\end{subequations}

\end{document}

答案2

(此答案基于上面“更正的 MWE”中提供的代码。)

我建议您加载mathtools包并使用几个\splitdfrac\splitfrac指令;请参阅下文以了解这个想法的应用。其次,我将用替换符号e^{...}\exp(...)否则阅读第二级上标材料就不容易了。第三,我将使用\bigl\bigr来增加一些(但肯定不是全部)圆括号和方括号的大小。

在此处输入图片描述

\documentclass{article}  
\usepackage{mathtools} % for '\splitfrac' macro
\DeclareMathOperator{\E}{E} % expectations operator
\begin{document}
\begin{align}
\E_{q_2}(A,B)
&=\frac{1}{3n}\sum_{i=1}^{n}
\frac{\bigl[1-\exp\bigl(-\mu_{\!A}(x_i)\bigr)\bigr]\times
      \bigl[1-\exp\bigl(-\mu_{\!B}(x_i)\bigr)\bigr]}{%
 \biggl(\splitdfrac{%
 \bigl[1-\exp\bigl(-\mu_{\!A}(x_i)\bigr)\bigr]^2
+\bigl[1-\exp\bigl(-\mu_{\!B}(x_i)\bigr)\bigr]^2}{%
-\bigl[1-\exp\bigl(-\mu_{\!A}(x_i)\bigr)\bigr]\times
       \bigl[1-\exp\bigl(-\mu_{\!B}(x_i)\bigr)\bigr]}
 \biggr)} \notag\\[1ex]
&+\frac{\bigl[1-\exp\bigl(-(1-v_{\!A}(x_i))\bigr)\bigr]\times
        \bigl[1-\exp\bigl(-(1-v_{\!B}(x_i))\bigr)\bigr]}{%
 \biggl(\splitdfrac{%
  \bigl[1-\exp\bigl(-(1-v_{\!A}(x_i))\bigr)\bigr]^2
 +\bigl[1-\exp\bigl(-(1-v_{\!B}(x_i))\bigr)\bigr]^2}{%
 -\bigl[1-\exp\bigl(-(1-v_{\!A}(x_i))\bigr)\bigr]\times
         \bigl[1-\exp\bigl(-(1-v_{\!B}(x_i))\bigr)\bigr]}
 \biggr)} \notag\\[1ex]
&+\frac{%
 \biggl(\splitdfrac{%
   \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))\bigr)\bigr]}{%
   \times
   \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))\bigr)\bigr]}
 \biggr)}{%
 \left(\splitdfrac{%
   \splitfrac{%
   \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))\bigr)\bigr]^2}{%
  +\bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))\bigr)\bigr]^2}}{% 
   \splitfrac{%
   {}-{} % make this a binary rather than a unary operator... 
    \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))\bigr)\bigr]}{
    \times
    \bigl[1-\exp\bigl(-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))\bigr)\bigr]}}
 \right)}
\end{align}
\end{document}

答案3

我已经编辑了@mico 的代码,使其变得更短一些。

\documentclass{article}  
\usepackage{mathtools} % for '\splitfrac' macro
\DeclareMathOperator{\E}{E} % expectations operator
\DeclarePairedDelimiter{\parens}()
\DeclarePairedDelimiter{\sparens}[]

\newcommand{\myexp}[1]{\exp\parens[\big]{#1}}
\newcommand{\ome}[1]{\sparens[\big]{1-\myexp{#1}}}

\begin{document}
\begin{align}
\E_{q_2}(A,B)
&=\frac{1}{3n}\sum_{i=1}^{n}
\frac{\ome{-\mu_{\!A}(x_i)}\times
      \ome{-\mu_{\!B}(x_i)}}{%
 \biggl(\splitdfrac{%
 \ome{-\mu_{\!A}(x_i)}^2
+\ome{-\mu_{\!B}(x_i)}^2}{%
-\ome{-\mu_{\!A}(x_i)}\times
       \ome{-\mu_{\!B}(x_i)}}\biggr)} \notag\\[1ex]
&+\frac{\ome{-(1-v_{\!A}(x_i))}\times
        \ome{-(1-v_{\!B}(x_i))}}{%
 \biggl(\splitdfrac{%
  \ome{-(1-v_{\!A}(x_i))}^2
 +\ome{-(1-v_{\!B}(x_i)))}^2}{%
 -\bigl\{\ome{-(1-v_{\!A}(x_i))}\times
         \ome{-(1-v_{\!B}(x_i))}\bigr\}}
 \biggr)} \notag\\[1ex]
&+\frac{%
 \biggl(\splitdfrac{%
   \ome{-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))}}{%
   \times
   \ome{-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))}}
 \biggr)}{%
 \left(\splitdfrac{%
   \splitfrac{%
   \ome{-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))}^2}{%
  +\ome{-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))}^2}}{% 
   \splitfrac{%
   -\ome{-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))}}{
    \times
    \ome{-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))}\bigr\} }}
 \right)}
\end{align}
\end{document}

并且,由于边距较小,可以进一步净化代码:

\documentclass{article}  
\usepackage[margin=1in]{geometry}
\usepackage{mathtools} % for '\splitfrac' macro
\DeclareMathOperator{\E}{E} % expectations operator
\DeclarePairedDelimiter{\parens}()
\DeclarePairedDelimiter{\sparens}[]

\newcommand{\myexp}[1]{\exp\parens[\big]{#1}}
\newcommand{\ome}[1]{\sparens[\big]{1-\myexp{#1}}}

\newcommand{\rat}[2]{%
\frac{\ome{#1} \times \ome{#2}}{
\parens[\bigg]{\splitdfrac{\ome{#1}^2 + \ome{#2}^2}{- \ome{#1}\times \ome{#2}}}}
}


\begin{document}
\begin{multline}
\E_{q_2}(A,B)
=\frac{1}{3n}\sum_{i=1}^{n}
\rat{-\mu_{\!A}(x_i)}{-\mu_{\!B}(x_i)}
\\
+\rat{-(1-v_{\!A}(x_i))}{-(1-v_{\!B}(x_i))}\\
+
 \rat{-\frac{1}{2}(1+\mu_{\!A}(x_i)-v_{\!A}(x_i))}{%
   {-\frac{1}{2}(1+\mu_{\!B}(x_i)-v_{\!B}(x_i))}}.
\end{multline}
\end{document}

相关内容