# Using split inside array and vertical alignment

The below code produces this:

I want to get that second line top-aligned, so the $\frac{\partial^2g}{(\partial n^1_\mu)^2}$ and $\frac{\partial^2 g}{(\partial n^1_\sigma)^2}$ are on the same level. How can I accomplish this?

\usepackage{array}
\newcommand{\xm}{\overline{\mathbf{x}}}
\begin{document}

\setlength{\arraycolsep}{20pt}
$\begin{array}{l r} \displaystyle \frac{\partial g}{\partial n_\mu^1} = \partial_1f(\xm)\cdot \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} & \displaystyle \frac{\partial g}{\partial n^1_\sigma} = \partial_1f(\xm) \cdot \left( -\gamma_1 \frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \right) \\[20pt] \displaystyle \frac{\partial^2 g}{(\partial n^1_\mu)^2} = \partial^2_1f(\xm)\left( \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} \right)^2 & \begin{split} \frac{\partial^2 g}{(\partial n_\sigma^1)^2} = \partial_1 f(\xm) \cdot 2 \left( -\gamma_1 \frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^3} \right) \\ {} + \partial_1^2 f(\xm)\left( -\gamma_1 \frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \right)^2 \end{split} \\[20pt] \begin{split} \frac{\partial^2 g}{\partial n_\mu^1 \partial n_\sigma^1} = \partial_1f(\xm)\cdot \frac{-\gamma_1}{(\sigma_1 + n_\sigma^1)^2} \\ {} + \partial_1^2 f(\xm) \left( -\gamma_1 \frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \right) \\ {} \cdot \left( \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} \right) \end{split} \end{array}$

\end{document}

• Use aligned with option [t], not split. – egreg Jun 20 '18 at 22:21

I'd suggest using an alignat* environment in the place of array as you can have full control on the spacing between columns. I replaced split with aligned, which can take an optional argument for the vertical placement: t, c (the default) and b.

Also, I loaded esdiff to have a simplified typing of partial derivatives, and used the \widebar command from mathabx (without loading all the mathabx fonts), as I think it looks nicer than \overline. Finally the mleftright package gives a better spacing for large delimiters.

\documentclass{article}
\usepackage{mathtools, mleftright}
\usepackage{esdiff}

\DeclareFontFamily{U}{mathx}{\hyphenchar\font45}
\DeclareFontShape{U}{mathx}{m}{n}{
<-6> mathx5 <6-7> mathx6 <7-8> mathx7
<8-9> mathx8 <9-10> mathx9
<10-12> mathx10 <12-> mathx12
}{}
\DeclareSymbolFont{mathx}{U}{mathx}{m}{n}
\DeclareFontSubstitution{U}{mathx}{m}{n}

\DeclareMathAccent{\widebar}{0}{mathx}{"73}
\newcommand{\xm}{\widebar{\mathbf{x}}}

\begin{document}

\begin{alignat*}{2}
\diffp{ g}{{n_\mu^1}} & = \partial_1f(\xm)\cdot \frac{-\gamma_1}{\sigma_1 + n_\sigma^1}
&
\diffp{g}{{n^1_\sigma}} & = \partial_1f(\xm) \cdot \mleft( -\gamma_1 \frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \mright)
\1ex] \diffp[2]{g}{(n^1_\mu\smash{)}} & = \partial^2_1f(\xm)\left( \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} \right)^2 & \diffp[2]{g}{(n_\sigma^1\smash{)}} & = \begin{aligned}[t] & \partial_1 f(\xm) \cdot 2 \mleft( -\gamma_1 \frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^3} \mright) \\ \mathllap{{} +{}} & \partial_1^2 f(\xm)\mleft( -\gamma_1 \frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \mright)^{\mkern-5mu 2} \end{aligned} \\[1ex] \diffp{g}{{n_\mu^1}{n_\sigma^1}} & = \begin{aligned}[t] & \partial_1f(\xm)\cdot \frac{-\gamma_1}{(\sigma_1 + n_\sigma^1)^2} \\ \mathllap{{} + {}}& \partial_1^2 f(\xm) \left( -\gamma_1 \frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \right) \\ \mathllap{{} \cdot} &\mleft( \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} \mright) \end{aligned} \end{alignat*} \end{document}  Here's a different approach. One can avoide line breaks inside the subformulas entirely, by replacing the repeated elements \sigma_1+n_{\sigma}^1 and x_1 - \mu_1 - n_\mu^1 with, say, \xi and \phi. Then, use an array environment to typeset the five subformulas across just 3 instead of 6 lines. Do try to keep the sizes of the large parentheses consistent; I suggest using \Bigl( and Bigr( throughout. As @Bernard did in his answer, I suggest loading the esdiff package and using the \diffp macro to streamline the typesetting of the partial-differential terms. \documentclass{article} \usepackage{esdiff} % for \diffp macro \usepackage{array} % for \newcolumntype macro \newcolumntype{L}{>{\displaystyle}l} % automatic display-style math mode \newcolumntype{R}{>{\displaystyle}r} \newcolumntype{C}{>{{}}c<{{}}} % for columns with "=" symbols \newcommand{\xm}{\bar{\mathbf{x}}} \begin{document} Put \xi=\sigma_1+n_{\sigma}^1 and \phi=x_1 - \mu_1 - n_\mu^1. Then \[ \setlength\arraycolsep{0pt} \begin{array}{RCL @{\qquad} RCL} \diffp{g}{{n_\mu^1}} &=& \partial_1f(\xm) \Bigl(\frac{-\gamma^{}_1}{\xi} \Bigr) & \diffp{g}{{n^1_\sigma}} &=& \partial_1f(\xm) \Bigl( \frac{-\gamma^{}_1\phi}{\xi^2} \Bigr) \\[3ex] \diffp[2]{g}{(n^1_\mu)} &=& \partial^2_1f(\xm)\Bigl( \frac{-\gamma^{}_1}{\xi} \Bigr)^{\!2} & \diffp[2]{g}{(n_\sigma^1)} &=& \partial_1 f(\xm) \cdot 2 \Bigl( \frac{-\gamma^{}_1\phi}{\xi^3} \Bigr) + \partial_1^2 f(\xm) \Bigl( \frac{-\gamma^{}_1 \phi}{\xi^2} \Bigr)^{\!2} \\[3ex] \diffp{g}{{n_\mu^1}{n_\sigma^1}} &=& \multicolumn{4}{L}{% \partial_1f(\xm) \frac{-\gamma^{}_1}{\xi^2} + \partial_1^2 f(\xm) \Bigl( \frac{-\gamma^{}_1\phi}{\xi^2} \Bigr) \Bigl( \frac{-\gamma^{}_1}{\xi} \Bigr)} \end{array}

\end{document}


Addendum: If using abbreviation terms such as \xi and \phi isn't suitable, I'd like to suggest displaying the five partial-derivative expressions across five separate lines. That way, the reader's eye doesn't have to "hunt" across lines to take in the expression for each partial derivative. And, five rows is still one row less than in your original solution.

\documentclass{article}
\usepackage{amsmath} % for align* environment
\usepackage{esdiff}  % for \diffp macro
\usepackage{kpfonts} % Palatino clone
\newcommand{\xm}{\bar{\mathbf{x}}}

\begin{document}
\begin{align*}
\diffp{g}{{n_\mu^1}}
&= \partial_1 f(\xm) \biggl(\frac{-\gamma_1}{\sigma_1+n_{\sigma}^1} \biggr)
\\
\diffp{g}{{n^1_\sigma}}
&= \partial_1 f(\xm) \biggl( \frac{-\gamma_1(x_1 - \mu_1 - n_\mu^1)}{(\sigma_1+n_{\sigma}^1)^2} \biggr)
\\
\diffp[2]{g}{(n^1_\mu)}
&= \partial^2_1f(\xm)\biggl( \frac{-\gamma_1}{\sigma_1+n_{\sigma}^1} \biggr)^{\!2}
\\
\diffp[2]{g}{(n_\sigma^1)}
&= \partial_1 f(\xm) \cdot 2 \biggl( \frac{-\gamma_1(x_1 - \mu_1 - n_\mu^1)}{(\sigma_1+n_{\sigma}^1)^3} \biggr)
+\partial_1^2 f(\xm) \biggl( \frac{-\gamma_1 (x_1 - \mu_1 - n_\mu^1)}{(\sigma_1+n_{\sigma}^1)^2} \biggr)^{\!2}
\\
\diffp{g}{{n_\mu^1}{n_\sigma^1}}
&= \partial_1f(\xm) \biggl( \frac{-\gamma_1}{(\sigma_1+n_{\sigma}^1)^2} \biggr)
+\partial_1^2 f(\xm) \biggl( \frac{-\gamma_1(x_1 - \mu_1 - n_\mu^1)}{(\sigma_1+n_{\sigma}^1)^2} \biggr)
\biggl( \frac{-\gamma_1}{\sigma_1+n_{\sigma}^1} \biggr)
\end{align*}
\end{document}


You're lucky enough that the last equation (unsplit) is as wide as the top line. So I suggest to gather everything, with the first two pairs aligned (with a nested aligned for splitting the fourth equation).

\documentclass{article}
\usepackage{amsmath}

\newcommand{\xm}{\overline{\mathbf{x}}}

\begin{document}

\begin{gather*}
\begin{aligned}
\frac{\partial g}{\partial n_\mu^1}
&=\partial_1f(\xm)\cdot \frac{-\gamma_1}{\sigma_1 + n_\sigma^1}
&
\frac{\partial g}{\partial n^1_\sigma}
&=\partial_1f(\xm) \cdot \biggl( -\gamma_1 \frac{x_1
- \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \biggr)
\\[2ex]
\frac{\partial^2 g}{(\partial n^1_\mu)^2}
&= \partial^2_1f(\xm)\biggl( \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} \biggr)^{\!2}
&
\frac{\partial^2 g}{(\partial n_\sigma^1)^2}
&= \begin{aligned}[t]
&\partial_1 f(\xm) \cdot 2 \biggl( -\gamma_1 \frac{x_1 -
\mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^3} \biggr)
\\
&\quad + \partial_1^2 f(\xm)\biggl( -\gamma_1 \frac{x_1 -
\mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \biggr)^{\!2}
\end{aligned}
\end{aligned}
\\[2ex]
\frac{\partial^2 g}{\partial n_\mu^1 \partial n_\sigma^1}
= \partial_1f(\xm)\cdot \frac{-\gamma_1}{(\sigma_1 + n_\sigma^1)^2}
+ \partial_1^2 f(\xm) \biggl( -\gamma_1 \frac{x_1 -
\mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \biggr)
\cdot \biggl( \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} \biggr)
\end{gather*}

\end{document}


yet another way of looking at this. the second equaton on the second line will fit within the text width, so why not keep it on one line by itself? then a simple align* can be used.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\xm}{\overline{\mathbf{x}}}

\begin{document}

\begin{align*}
\frac{\partial g}{\partial n_\mu^1}
&= \partial_1f(\xm)\cdot \frac{-\gamma_1}{\sigma_1 + n_\sigma^1}
\frac{\partial g}{\partial n^1_\sigma}
=\partial_1f(\xm) \cdot \biggl( -\gamma_1
\frac{x_1  - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \biggr)\\[2\jot]
\frac{\partial^2 g}{(\partial n^1_\mu)^2}
&= \partial^2_1f(\xm)\biggl( \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} \biggr)^{\!2}\\[2\jot]
\frac{\partial^2 g}{(\partial n_\sigma^1)^2}
&= \partial_1 f(\xm) \cdot 2 \biggl( -\gamma_1
\frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^3} \biggr)
+ \partial_1^2 f(\xm)\biggl( -\gamma_1
\frac{x_1 - \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \biggr)^{\!2}
\\[2\jot]
\frac{\partial^2 g}{\partial n_\mu^1 \partial n_\sigma^1}
&= \partial_1f(\xm)\cdot \frac{-\gamma_1}{(\sigma_1 + n_\sigma^1)^2}
+ \partial_1^2 f(\xm) \biggl( -\gamma_1
\frac{x_1 -  \mu_1 - n_\mu^1}{(\sigma_1 + n_\sigma^1)^2} \biggr)
\cdot \biggl( \frac{-\gamma_1}{\sigma_1 + n_\sigma^1} \biggr)
\end{align*}

\end{document}


this applies fixed sizing to the parentheses (\bigg is usually a good choice for fractions of this sort). it also uses a multiple of the dimension \jot to specify the line separation; 1\jot is the default separation for align, and actually, with the equations laid out like this, extra separation isn't really needed.