6

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}
2
  • 1
    If you really want to do that with arrays, you could load the array package and do \begin{array}{rc>{\displaystyle}l}
    – LaRiFaRi
    Jun 16, 2015 at 7:25
  • @LaRiFaRi That's a good suggestion, I already use array to define new column types for elsewhere in the document. I'm not attached to the array environment here, just the alignment I've achieved with it. If another suggestion comes up without using \begin{array} I'll look at that too. Jun 16, 2015 at 7:37

3 Answers 3

5

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

1
  • 1
    Excellent. +1 for the no-array version from me too. I'd gone away overnight and done much the same thing with nested \begin{aligned} environments, but this is done better. I forgot to check that I could seperate \left. and \right\{ by alignments characters (&) now that I'd gotten rid of pesky array's The way it's done here minimises \*phantom spacing, and still gets the nice alignment of the equation and the descriptive braces. Jun 16, 2015 at 23:56
1

Here's a general option which addresses your concern. That is, a localized change from inline to display style mathematical typesetting. The easier option for the case you're using array is adjusting the argument thereof (as mentioned in the comments).

The solution opens a group, and redefines the macros you wish to be \displaystyle. After the group closes the redefinitions are also reset.

In your case, you may need to readjust the arraystretch to make sure no symbols overlap between lines. (\renewcommand\arraystretch{<factor>} somewhere between \begingroup and \endgroup).

Here's a screenshot from the output. Notice how the inline math below the array has the "standard inline" math style.

enter image description here

\documentclass[a4paper]{book}
\usepackage{mathtools}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begingroup
\let\oldsum\sum
\let\oldfrac\frac
\def\sum{\displaystyle\oldsum}
\def\frac{\displaystyle\oldfrac}
   \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}
\endgroup
$\sum_{\text{bonds},\, i} K_{b,i} \left( b_i - b_{0,i} \right)^2$
\lipsum[2-3]
\end{document}
7
  • Hmm, I like the re-definition of the \sum and \frac commands. As far as I can see the outermost environment should be a display-type environment already, so I don't see why my original code should be typesetting maths in inline mode in the first place. Jun 16, 2015 at 7:44
  • It's a shame it has to be attached to the equation in question and not a global option for the document. Jun 16, 2015 at 7:50
  • @tmgriffiths You can make it global without the \begingroup and \endgroup. If you then want to revert your inline mathematics locally, just open a group and use \let\sum\oldsum and \let\frac\oldfrac to get the old definitions again.
    – 1010011010
    Jun 16, 2015 at 7:52
  • 2
    @tmgriffiths Inside an array, math should be inline, not display. The concern inside array is that displaymath causes parts of the mathematics affected by the displaystyle command to overflow to the line above or below. Other than that, I'm unsure how to put your phrasing "It should be display math".
    – 1010011010
    Jun 16, 2015 at 7:58
  • 2
    @tmgriffiths array is essentially designed for matrices and the like, you should be using a displayed alignment environment such as aligned from amsmath then entries will be in display math by default. Jun 16, 2015 at 8:17
1

Here's a solution that maintains your basic array setup, while simplifying it somewhat. Inside the equation, it first defines two scratch macros, \blocka and \blockb, and then uses each of them twice: first to typeset the material itself, then as the argument of the \vphantom instructions. Each "block" macro consists of an array environment that contains two columns. Extra care is taken to align the + symbols and the summation symbols and to provide a bit of vertical whitespace between the two big blocks.

enter image description here

\documentclass[a4paper]{book}
\usepackage{mathtools,array}
\usepackage{booktabs} % for "\addlinespace" macro
\begin{document}
\hrule % just to illustrate width of text block
\begin{equation}
\setlength\extrarowheight{1ex}
    %% Set up two scratch macros, \blocka and \blockb, for the bonded 
    %% and non-bonded terms, respectively
    \newcommand\blocka{% bonded terms
    \begin{array}{r @{} >{\displaystyle}l} % 2nd column in displaystyle
         U  ={}& \phantom{+\quad}\smashoperator[l]{\sum_{\text{bonds},\, i}} K_{b,i} ( b_i - b_{0,i} )^2 \\
               &+\quad \smashoperator[l]{\sum_{\text{angles},\, i}}
                  K_{\theta,i} (\theta_i -\theta_{0,i})^2 \\
               &+\quad \smashoperator[l]{\sum_{\text{dihedrals},\, i}}
                  K_{\phi,i} ( 1 - \cos( n\phi_i - \phi_{0,i} ) ) \\
               &+\quad \smashoperator[l]{\sum_{%
                  \substack{\text{improper},\, i\\ \text{dihedrals}}}} 
                  K_{\omega,i} ( \omega_i - \omega_{0,i} )^2 \\
    \end{array}}
    \newcommand\blockb{% non-bonded terms
    \begin{array}{r @{} >{\displaystyle}l} % 2nd column in displaystyle
        \phantom{U  ={}}
            &+\quad \smashoperator[l]{\sum_{\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] \\ \addlinespace
            &+\quad \smashoperator[l]{\sum_{\text{atoms},\, i,j}}
                        \frac{1}{4\pi\epsilon_0\epsilon_r}
                        \frac{q_i q_j}{ r_{ij} }
   \end{array}}
   %% Now typeset the material in the two big blocks
   \begin{array}{ll} 
       \blocka & \left. \vphantom{\blocka} \right\} \text{bonded} \\ 
       \addlinespace
       \blockb & \left. \vphantom{\blockb} \right\} \text{non-bonded}
   \end{array}
   \end{equation}

\hrule  % just to illustrate width of text block
\end{document} 

You must log in to answer this question.

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