# Nested matrices; inner matrices too tall when switching math font

I have used this answer https://tex.stackexchange.com/a/61290/46626 to adjust my matrices and it works fine with the standard font (Latin Modern Math)

But when I use Cambria Math, the inner matrices seem to be too tall:

I am not able to fix that, does anybody have an idea? Is it possible to use it as an standard matrix style? I am using TeX Live 2016 and LuaLaTeX. Other solution for a proper setting of this matrices are also welcome. Thanks!

MWE:

\documentclass{article}

\usepackage{fontspec}
\usepackage{mathtools} % includes: \usepackage{amsmath} (-> needed e.g. for bmatrix) !! load BEFORE \usepackage{unicode-math}
\usepackage{unicode-math}   %Unicode mathematics support for X∃TEX and LuaTEX

%% Set font
%\setromanfont{Cambria}
%\setsansfont{Calibri}
%\setmonofont{Consolas}
%\setmathfont{Cambria Math}

\makeatletter
\newif\ifcenter@asb@\center@asb@false
\def\center@arstrutbox{%
\setbox\@arstrutbox\hbox{$\vcenter{\box\@arstrutbox}$}%
}
\newcommand*{\CenteredArraystretch}[1]{%
\ifcenter@asb@\else
\pretocmd{\@mkpream}{\center@arstrutbox}{}{}%
\center@asb@true
\fi
\renewcommand{\arraystretch}{#1}%
}
\makeatother

\begin{document}

$$\CenteredArraystretch{1.2} \delimitershortfall=-2pt %\renewcommand*{\arraystretch}{1.2} %Default is 1.0 \begin{split} \begin{bmatrix} \begin{bmatrix} m & 0\\ 0 & m \end{bmatrix}& -m\, \mathbfit{A}^{RL} \begin{bmatrix} \phantom{-}y^L_{P_{\mathrm{COG}}O_L}\\ -x^L_{P_{\mathrm{COG}}O_L} \end{bmatrix}\\ -m \begin{bmatrix} y^L_{P_{\mathrm{COG}}O_L} & -x^L_{P_{\mathrm{COG}}O_L} \end{bmatrix} \mathbfit{A}^{LR}& J^L + m\left(\left(x^L_{P_{\mathrm{COG}}O_L}\right)^2 + \left(y^L_{P_{\mathrm{COG}}O_L}\right)^2 \right) \end{bmatrix} \begin{bmatrix} \begin{bmatrix} \ddot{x}^R_{O_LO_R}\\ \ddot{y}^R_{O_LO_R} \end{bmatrix}\\%[2ex] \ddot{\psi} \end{bmatrix} = \\ \begin{bmatrix} \sum \begin{bmatrix} F^R_{ix}\\ F^R_{iy} \end{bmatrix}\\ \sum M^L_{iz}+\sum \begin{bmatrix} -y^L_{PiP} & x^L_{PiP} \end{bmatrix} \begin{bmatrix} F^L_{ix}\\ F^L_{iy} \end{bmatrix} \end{bmatrix} + \begin{bmatrix} m\,\mathbfit{A}^{RL} \begin{bmatrix} x^L_{P_{\mathrm{COG}}O_L}\\ y^L_{P_{\mathrm{COG}}O_L} \end{bmatrix} \dot{\psi}^2\\%[2ex] 0 \end{bmatrix} \end{split}$$

\end{document}


Update: Using Mico's answer, I (almost) found the desired result. But it needs a lot of manual adjustment and I wonder if there is a simpler solution?

\documentclass{article}

\usepackage{fontspec}
\usepackage{mathtools} % includes: \usepackage{amsmath} (-> needed e.g. for bmatrix) !! load BEFORE \usepackage{unicode-math}
\usepackage{unicode-math}   %Unicode mathematics support for X∃TEX and LuaTEX

% Set font
\setmainfont{Cambria}
\setmathfont{Cambria Math}
\setsansfont{Calibri}
\setmonofont{Consolas}

\begin{document}
\begin{multline}
\delimitershortfall=-2pt \renewcommand{\arraystretch}{1.33}
\begin{bmatrix}
\delimitershortfall=5pt
\begin{bmatrix}
m & 0\\
0 & m
\end{bmatrix} &
-m\, \mathbfit{A}^{RL}
\delimitershortfall=5pt
\begin{bmatrix}
\phantom{-}y^L_{P_{\mathrm{COG}}O_L} \\
-x^L_{P_{\mathrm{COG}}O_L}
\end{bmatrix} \\[3ex]
-m \begin{bmatrix}
y^L_{P_{\mathrm{COG}}O_L} &
-x^L_{P_{\mathrm{COG}}O_L}
\end{bmatrix}
\mathbfit{A}^{LR} &
J^L + m\bigl(
(x^L_{P_{\mathrm{COG}}O_L})^2 +
(y^L_{P_{\mathrm{COG}}O_L})^2
\bigr)
\end{bmatrix}\,
\begin{bmatrix}
\delimitershortfall=5pt
\begin{bmatrix}
\ddot{x}^R_{O_LO_R}\\
\ddot{y}^R_{O_LO_R}
\end{bmatrix} \\[3.25ex]
\ddot{\psi}
\end{bmatrix} \\[2ex]  % end of first row
\delimitershortfall=-2pt
=\begin{bmatrix}
\sum\limits_{i} \begin{bmatrix}
F^R_{ix} \\[0.5ex]
F^R_{iy}
\end{bmatrix}\\
\sum\limits_{i} M^L_{iz}+
\sum\limits_{i} \begin{bmatrix}
-y^L_{PiP} & x^L_{PiP}
\end{bmatrix}
\begin{bmatrix}
F^L_{ix} \\[0.5ex] F^L_{iy}
\end{bmatrix}
\end{bmatrix}
+
\begin{bmatrix}
m\,\mathbfit{A}^{RL}
\begin{bmatrix}
x^L_{P_{\mathrm{COG}}O_L} \\[0.5ex]
y^L_{P_{\mathrm{COG}}O_L}
\end{bmatrix}
\dot{\psi}^2 \\[4.5ex]
0
\end{bmatrix}
\end{multline}
\end{document}


• The first row in the upper screenshot is much wider than the textblock. Is this intentional? Aside: Is \sum correct? Should it maybe be \Sigma? Please advise. – Mico Jun 13 '18 at 18:33
• BTW, \setromanfont is deprecated; use \setmainfont instead. – Mico Jun 13 '18 at 18:40
• Thanks for the hint. The sum is correct (sum of forces/moments). I'm sorry that was a typo, i just upgraded from TeXLive2017 to TeXLive2018 before posting this question. – Konne Jun 14 '18 at 8:07

(Tested with LuaLaTeX from TeXLive2018. Note: LuaTeX and unicode-math have evolved greatly between TeXLive2016 and TeXLive2018. If at all feasible, do consider updating to TeXLive2018.)

I don't think it's necessary to change \delimitershortfall, which is a the very-low-level parameter. Instead, change the value of \arraystretch and add a few extra vertical spacing directives as needed. Since there's no obvious alignment point across rows, I'd use a multline environment instead of the nested equation/split environments. Also, no need to use \left and \right to auto-size some of the parentheses.

\documentclass{article}
\usepackage{mathtools}
% Set fonts
\usepackage{unicode-math}
\setmainfont{Cambria}
\setmathfont{Cambria Math}
\setsansfont{Calibri}
\setmonofont{Consolas}

\begin{document}

\begin{multline}
\renewcommand{\arraystretch}{1.33}
\begin{bmatrix}
\begin{bmatrix}
m & 0\\
0 & m
\end{bmatrix} &
-m\, \mathbfit{A}^{RL}
\begin{bmatrix}
\phantom{-}y^L_{P_{\mathrm{COG}}O_L} \\
-x^L_{P_{\mathrm{COG}}O_L}
\end{bmatrix} \\[3ex]
-m \begin{bmatrix}
y^L_{P_{\mathrm{COG}}O_L} &
-x^L_{P_{\mathrm{COG}}O_L}
\end{bmatrix}
\mathbfit{A}^{LR} &
J^L + m\bigl(
(x^L_{P_{\mathrm{COG}}O_L})^2 +
(y^L_{P_{\mathrm{COG}}O_L})^2
\bigr)
\end{bmatrix}\,
\begin{bmatrix}
\begin{bmatrix}
\ddot{x}^R_{O_LO_R}\\
\ddot{y}^R_{O_LO_R}
\end{bmatrix} \\[3.25ex]
\ddot{\psi}
\end{bmatrix} \\[2ex]  % end of first row
=\begin{bmatrix}
\sum \begin{bmatrix}
F^R_{ix} \\[0.5ex]
F^R_{iy}
\end{bmatrix}\\
\sum M^L_{iz}+
\sum \begin{bmatrix}
-y^L_{PiP} & x^L_{PiP}
\end{bmatrix}
\begin{bmatrix}
F^L_{ix} \\[0.5ex] F^L_{iy}
\end{bmatrix}
\end{bmatrix}
+
\begin{bmatrix}
m\,\mathbfit{A}^{RL}
\begin{bmatrix}
x^L_{P_{\mathrm{COG}}O_L} \\[0.5ex]
y^L_{P_{\mathrm{COG}}O_L}
\end{bmatrix}
\dot{\psi}^2 \\[4.5ex]
0
\end{bmatrix}
\end{multline}

\end{document}

• Thanks, this already looks really good with the multiline environment. There is only one problem left, I used \delimitershortfall in order to get the outer matrix bigger than the inner (in my opinion it looks ugly how the matrix above \ddot{\psi} protrudes the outer). If I insert \delimitershortfall, I have the same problem as in the question. Do you have an idea how to solve this? – Konne Jun 14 '18 at 8:24
• @Konne - Try setting \delimitershortfall=-1pt and, in turn, not changing the value of \arraystretch. The brackets around the inner arrays in the upper row will no longer protrudevertically; they will still protrude, but only barely noticeably, in the lower row. About the summation symbols: To make it clear(er) to readers that summations are being applied, consider changing \sum to sum_i (or whater the appropriate summation index is). – Mico Jun 14 '18 at 9:27
• Thanks, I have changed the sum. Unfortunately e.g. the  m & 0\\0 & m matrix is still too tall. I found a solution, but many \delimitershortfall commands are needed :(. I will add this to the question. – Konne Jun 14 '18 at 13:00