3

I'm trying to write a matrix that contains two items with a fraction inside of it. I see that the matrix output is pretty strange because the rows and columns are not spaced with the same scale.

Besides of that, the fraction seems to take up too much space, and I have tried to reduce the font with size commands, but it seems they don't work in math mode. The code I wrote is the following:

\begin{align*}
Q= \begin{pmatrix}
\dfrac{1}{\Delta \alpha^2_{\mathrm{max}}} & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & \dfrac{1}{\Delta h^2_{\mathrm{max}}}
\end{pmatrix}
\end{align*}

And the output is the following:

Output

Any ideas to improve the output?

4

First of all, you can use \frac instead of \dfrac to shrink fractions in a matrix environment.

One option, inspired by this answer, uses the tabstackengine package:

\documentclass{article}

\usepackage{tabstackengine}
\stackMath

\begin{document}
\[
\setstackgap{L}{1.1\baselineskip}
\fixTABwidth{T}
Q= \parenMatrixstack{
    \frac{1}{\Delta \alpha^2_{\mathrm{max}}} & 0 & 0 & 0\\
    0 & 0 & 0 & 0\\
    0 & 0 & 0 & 0\\
    0 & 0 & 0 & \frac{1}{\Delta h^2_{\mathrm{max}}}
}
\]
\end{document}

enter image description here

  • 2
    Consider growing the stackgap from 1.1 to, maybe, 1.3 \baselineskip. Needless to say, I like this answer. – Steven B. Segletes May 12 '16 at 17:02
  • 1
    Thank you so much! This is one is super nice aligned. What I needed! Yeah 1.3 \baselineskip gives a better output, but it's fine! – Airman01 May 12 '16 at 17:06
  • 1
    off-topic: instead of write \alpha^2_{\mathrm{max}} is sufficient to write \alpha^2_{\max}. – Zarko May 12 '16 at 17:08
6

I suggest increasing \arraystretch, and using the \mfrac command (medium sized fraction, about 80 % of \displaystyle), from nccmath. If you want all columns to have the qame width, it can be done with the eqparbox package. Also, note \max is a math operator, so you don't need to code _{\mathrm{max}}:

\documentclass{article}
\usepackage{mathtools, array, nccmath, eqparbox}
\newcommand\eqmathbox[2][cw]{\eqmakebox[#1]{\ensuremath{#2}}}

\begin{document}

\[ \renewcommand\arraystretch{1.333}%
 Q= \begin{pmatrix}
\mfrac{1}{\Delta h^2_{\max}} & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & \mfrac{1}{\Delta h^2_{\max}}
\end{pmatrix}
 \]%
\vskip2ex
\[ \renewcommand\arraystretch{1.333}\setlength\arraycolsep{0pt}%
 Q= \left(\begin{array}{cccc} \eqmathbox{\mfrac{1}{\Delta h^2_{\max}}} & \eqmathbox{0} & \eqmathbox{0} & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & 0\\
0 & 0 & 0 & \eqmathbox{\mfrac{1}{\Delta h^2_{\max}}}
\end{array}\right)
 \]%
\end{document} 

enter image description here

  • Thank you very much! That was exactly what I was looking for!! – Airman01 May 12 '16 at 17:05
  • @barbara beeton: You can't reproduce it. It's just that I mingled the true image with a previous attempt. I'll correct it in a moment. Thank you for pointing it! – Bernard May 12 '16 at 17:26

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.