[Tex/LaTex] Display math gets typeset as inline math

arraysdisplaystyleinline()math-modemathtools

When typesetting the below annotated equation my summations are being typeset as inline maths rather than display maths.
Inline sumations, curse you!

  • If I wrap the sum and subscript with \smashoperator{} then they are typeset correctly as display math again.
  • I've tried multiple outermost wrappers for the array of arrays,
    • \begin{equation},
    • \begin{align} starred and unstarred,
    • \[ ... \],
    • \begin{gather}.

I'm aware of the existance of the \displaystyle macro, I don't want to set it globally if at all posible, I have inline maths elsewhere in my document. In all honesty I'd like to find out what I'm doing wrong and fix that rather than stick a macro in there to fix my poor tex-ing).

I compile my document with LuaLaTeX, MWE follows.

\documentclass[a4paper]{book}
\usepackage{mathtools}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
   \begin{equation}
   \begin{array}{ll} % array to ensure the force field and the braces are aligned, as the non-bonded terms are a little wider than the bonded.
      \begin{array}{rcl} % bonded terms.
         U  &=& \sum_{\text{bonds},\, i} K_{b,i} \left( b_i - b_{0,i} \right)^2 \\
            &+& \sum_{\text{angles},\, i} K_{\theta,i} \left( \theta_i - \theta_{0,i} \right)^2 \\
            &+& \sum_{\text{dihedrals},\, i}%
               K_{\phi,i} \left( 1 - \cos\left( n\phi_i - \phi_{0,i} \right) \right) \\
            &+& \sum_{%
               \substack{\text{improper},\, i\\ \text{dihedrals}}%
               } K_{\omega,i} \left( \omega_i - \omega_{0,i} \right)^2 \\
   \end{array}%
   & \left. \vphantom{% Phantom content to make brace correct size. \left. \right\} Havent worked when across two columns in array...
               \begin{array}{rcl}
                  U  &=& \sum_{\text{bonds},\, i} K_{b,i} \left( b_i - b_{0,i} \right)^2 \\
                     &+& \sum_{\text{angles},\, i} K_{\theta,i} \left( \theta_i - \theta_{0,i} \right)^2 \\
                     &+& \sum_{\text{dihedrals},\, i}%
                        K_{\phi,i} \left( 1 - \cos\left( n\phi_i - \phi_{0,i} \right) \right) \\
                     &+& \sum_{%
                        \substack{\text{improper},\, i\\ \text{dihedrals}}%
                        } K_{\omega,i} \left( \omega_i - \omega_{0,i} \right)^2 \\
               \end{array}
               }%
   \right\} \text{bonded} \\
   \begin{array}{rcl} % non-bonded terms.
      \hphantom{U}   &+& \sum_{\text{atoms},\, i,j} \epsilon_{ij}%
                        \left[%
                           \left(%
                              \frac{ r^{min}_{ij} } { r_{ij} }%
                           \right)^{12}%
                           -2 \left(%
                              \frac{ r^{min}_{ij} }{ r_{ij} }%
                           \right)^6%
                        \right] \\
                     &+& \sum_{\text{atoms},\, i,j}%
                        \frac{1}{4\pi\epsilon_0\epsilon_r}\frac{q_i q_j}{ r_{ij} }
   \end{array}%
   & \left. \vphantom{% Phantom content to make brace correct size. \left. \right\} Havent worked when across two columns in array...
               \begin{array}{rcl} % non-bonded terms.
                  \phantom{U} &+& \sum_{\text{atoms},\, i,j} \epsilon_{ij}%
                                 \left[%
                                    \left(%
                                       \frac{ r^{min}_{ij} } { r_{ij} }%
                                    \right)^{12}%
                                    -2 \left(%
                                       \frac{ r^{min}_{ij} }{ r_{ij} }%
                                    \right)^6%
                                 \right] \\
                              &+& \sum_{\text{atoms},\, i,j}%
                                 \frac{1}{4\pi\epsilon_0\epsilon_r}\frac{q_i q_j}{ r_{ij} }
               \end{array}
               }%
   \right\} \text{non-bonded}
   \end{array}
   \end{equation}

\lipsum[2-3]
\end{document}

Best Answer

You can add \displaystyle to the columns you like in your array:

% arara: pdflatex

\documentclass[a4paper]{book}
\usepackage{mathtools}
\usepackage{lipsum}
\usepackage{array}

\begin{document}
    \lipsum[1]
    \begin{equation}
    \begin{aligned}
    &\left.\begin{array}{r@{\;}>{{}\displaystyle}l}
    U  =& \sum_{\mathclap{\text{bonds},\,i}} K_{b,i} ( b_i - b_{0,i})^2 \\
    &+ \sum_{\mathclap{\text{angles},\, i}} K_{\theta,i} ( \theta_i - \theta_{0,i} )^2 \\
    &+ \sum_{\mathclap{\text{dihedrals},\, i}}  K_{\phi,i} \bigl( 1 - \cos( n\phi_i - \phi_{0,i} ) \bigr) \\
    &+ \mathrlap{\sum_{\mathclap{\substack{\text{improper},\, i\\ \text{dihedrals}}}} K_{\omega,i} ( \omega_i - \omega_{0,i} )^2 }
    \hphantom{\sum_{\mathclap{\text{atoms},\,i,j}}\epsilon_{ij}\Biggl[\biggl(\frac{r^{\min}_{ij}}{r_{ij}}\biggr)^{12}-2\biggl(\frac{r^{\min}_{ij}}{r_{ij}}\biggr)^6\Biggr]}
    \end{array}\right\}\text{bonded}\\
    &\left.\begin{array}{r@{\;}>{{}\displaystyle}l}
    \hphantom{U =}
    &+\sum_{\mathclap{\text{atoms},\,i,j}}\epsilon_{ij}\Biggl[\biggl(\frac{r^{\min}_{ij}}{r_{ij}}\biggr)^{12}-2\biggl(\frac{r^{\min}_{ij}}{r_{ij}}\biggr)^6\Biggr] \\
    &+\sum_{\mathclap{\text{atoms},\, i,j}}(4\pi\epsilon_0\epsilon_r)^{-1}\frac{q_i q_j}{ r_{ij}}
    \end{array}\right\}\text{non-bonded}
    \end{aligned}
    \end{equation}
    \lipsum[2-3]
\end{document}

enter image description here


If you were just concerned about the limits of your sum-symbols, you could add the command \limits to each of them. Safes you some space.

\begin{equation}
\begin{aligned}
&\left.\begin{array}{r@{\;}>{{}}l}
U =&\sum\limits_{\mathclap{\text{bonds},\,i}} K_{b,i} ( b_i - b_{0,i})^2 \\
&+ \sum\limits_{\mathclap{\text{angles},\, i}} K_{\theta,i} ( \theta_i - \theta_{0,i} )^2 \\
&+ \sum\limits_{\mathclap{\text{dihedrals},\, i}}   K_{\phi,i}\bigl( 1 - \cos( n\phi_i - \phi_{0,i} ) \bigr) \\
&+ \mathrlap{\sum\limits_{\mathclap{\substack{\text{improper},\, i\\ \text{dihedrals}}}} K_{\omega,i} ( \omega_i - \omega_{0,i} )^2 }
\hphantom{\sum\limits_{\mathclap{\text{atoms},\,i,j}}\epsilon_{ij}\biggl[\Bigl(\frac{r^{\min}_{ij}}{r_{ij}}\Bigr)^{12}-2\Bigl(\frac{r^{\min}_{ij}}{r_{ij}}\Bigr)^6\biggr]}
\end{array}\right\}\text{bonded}\\
&\left.\begin{array}{r@{\;}>{{}}l}
\hphantom{U =}
&+\sum\limits_{\mathclap{\text{atoms},\,i,j}}\epsilon_{ij}\biggl[\Bigl(\frac{r^{\min}_{ij}}{r_{ij}}\Bigr)^{12}-2\Bigl(\frac{r^{\min}_{ij}}{r_{ij}}\Bigr)^6\biggr] \\
&+\sum\limits_{\mathclap{\text{atoms},\, i,j}}(4\pi\epsilon_0\epsilon_r)^{-1}\frac{q_i q_j}{ r_{ij}}
\end{array}\right\}\text{non-bonded}
\end{aligned}
\end{equation}

This would look like

enter image description here


However, personally I would not set such things as an array, as those are meant for matrices and alike. You could just nest two aligned which will result in display style as well.

\begin{equation}
\begin{aligned}
&\left.\begin{aligned}
U  ={}& \sum_{\mathclap{\text{bonds},\,i}} K_{b,i} ( b_i - b_{0,i})^2 \\
&+ \sum_{\mathclap{\text{angles},\, i}} K_{\theta,i} ( \theta_i - \theta_{0,i} )^2 \\
&+ \sum_{\mathclap{\text{dihedrals},\, i}}  K_{\phi,i} \bigl( 1 - \cos( n\phi_i - \phi_{0,i} ) \bigr) \\
&+ \mathrlap{\sum_{\mathclap{\substack{\text{improper},\, i\\ \text{dihedrals}}}} K_{\omega,i} ( \omega_i - \omega_{0,i} )^2 }
\hphantom{\sum_{\mathclap{\text{atoms},\,i,j}}\epsilon_{ij}\Biggl[\biggl(\frac{r^{\min}_{ij}}{r_{ij}}\biggr)^{12}-2\biggl(\frac{r^{\min}_{ij}}{r_{ij}}\biggr)^6\Biggr]}
\end{aligned}\right\}\text{bonded}\\
&\left.\begin{aligned}
\hphantom{U ={}}
&+\sum_{\mathclap{\text{atoms},\,i,j}}\epsilon_{ij}\Biggl[\biggl(\frac{r^{\min}_{ij}}{r_{ij}}\biggr)^{12}-2\biggl(\frac{r^{\min}_{ij}}{r_{ij}}\biggr)^6\Biggr] \\
&+\sum_{\mathclap{\text{atoms},\, i,j}}(4\pi\epsilon_0\epsilon_r)^{-1}\frac{q_i q_j}{ r_{ij}}
\end{aligned}\right\}\text{non-bonded}
\end{aligned}
\end{equation}

You can see that the vertical spacing is much more pleasant (but you could treat that manually for all cases, of course):

enter image description here

Related Question