[Tex/LaTex] Avoiding overlapping superscripts and subscripts in matrices

matricessubscriptssuperscripts

I was working on some calculus today and tried to typeset a matrix of partial derivatives and ran into some trouble. Here is my code:

\documentclass{minimal}
\usepackage{mathtools}
\begin{document}
\begin{equation}
\begin{pmatrix}
    \frac{\partial f^1}{\partial x_1}   & \frac{\partial f^1}{\partial x_2}\\
    \frac{\partial f^2}{\partial x_1}   & \frac{\partial f^2}{\partial x_2}
\end{pmatrix}
\end{equation}
\end{document}

As can be seen, the output results in the subscripts from the denominators of the top row on the matrix with the superscripts from the numerators of the bottom row on the matrix. Is there an easy way to avoid this?

Best Answer

The cellspace package defines 2 lengths, \cellspacetoplimit and \cellspacebottomlimit that are the minimal vertical white space between the top of a cell and the bottom of the above cell, and between the bottom of a cell and the top of the below cell. Here is a example:

    \documentclass{minimal}
    \usepackage{mathtools}

    \usepackage[math]{cellspace}
    \cellspacetoplimit 3pt
    \cellspacebottomlimit 3pt
    \setlength{\arraycolsep}{4pt}
    \begin{document}
    \[
    \begin{pmatrix}
        \dfrac{\partial f^1}{\partial x_1}   & \dfrac{\partial f^1}{\partial x_2}\\
        \dfrac{\partial f^2}{\partial x_1}   & \dfrac{\partial f^2}{\partial x_2}
    \end{pmatrix}
    \]

    \cellspacetoplimit 0pt
    \cellspacebottomlimit 0pt
    \[
    \begin{pmatrix}
        \dfrac{\partial f^1}{\partial x_1}   & \dfrac{\partial f^1}{\partial x_2}\\
        \dfrac{\partial f^2}{\partial x_1}   & \dfrac{\partial f^2}{\partial x_2}
    \end{pmatrix}
    \]
    \end{document} 

enter image description here

It works with the amsmath environments (matrix, &c.), but not, unfortunately, with their starred versions defined by mathtools.