Is it possible to adjust the padding around elements in a matrix, as indicated in the figure below.

Example of cramped matrix

The code is shown below



... in general we have

        \frac{\partial f_1}{\partial x_1} & \cdots &
        \frac{\partial f_1}{\partial x_n} \\
        \vdots & \ddots & \vdots \\
        \frac{\partial f_m}{\partial x_1} & \cdots &
        \frac{\partial f_m}{\partial x_n}

and for the particular case of $m=n=2$ 

        \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}

Is it possible to insert some space around the elements in (2)? The matrix looks a bit cramped.

  • The cellspace package wiith option [math] does that.
    – Bernard
    Sep 20, 2020 at 9:29
  • The package nicematrix provides tools to control that and also many other points. Sep 20, 2020 at 9:48

1 Answer 1


Here's a code with cellspace. Unrelated: I suggest using the diffcoeff package to simplify typing of partial derivatives, and the \medmath command from nccmath to have medium-sized fractions in matrices (the default is \tfrac):

\usepackage{amsmath, nccmath}


\[ J = \begin{pmatrix}
        \medmath{\diffp{f_1}{x_1}} & \medmath{\diffp{f_1}{x_2}} \\
         \medmath{\diffp{f_2}{x_1}} & \medmath{\diffp{f_2}{x_2}}


enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.