1

I am trying to write custom commands to allow faster writing of 2 by 2 matrices without having to use array each time I need that. The output is good, but since the matrices will be a part of larger table, it is good to minimize the height by removing some of the unwanted vertical space added above and below the contents inside the array.

Also, the result below show very small distance between the matrix itself and the line of the fraction. For someone looking far away, it may look as though there is nothing that separates the matrix from the fraction line.

enter image description here

\documentclass{book}

\usepackage{mathtools}

\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\matTwoByTwo}[4]{
    \renewcommand{\arraystretch}{1}
    \begin{array}{@{\thinspace}c @{\thinspace\thinspace\thinspace}c@{\thinspace}}
        #1 & #2
        \\
        #3 & #4
    \end{array}
}

\newcommand{\matTwoByTwoAbs}[4]{
\abs{\matTwoByTwo{#1}{#2}{#3}{#4}}
}

\begin{document}

\begin{equation}
    \frac{\matTwoByTwoAbs{a_{4}}{a_{2}}{a_{3}}{a_{1}}}{a_{3}}
\end{equation}

\end{document}
3
  • beware that macro definitions do not form a group so your \matTwoByTwoAbs command \renewcommand{\arraystretch}{1} will stretch all following arrays in the same group, not just the current one. Oct 13, 2019 at 20:54
  • If all your matrix elements are simple, like those in your example, you could use \Bigl| ... \Bigr| or \biggl| ... \biggr| instead of \left| ... \right|. (The latter almost always make the fences too big.) But you shouldn't just redefine \abs with fixed sizes, because that could give a wrong size in other situations. Oct 13, 2019 at 21:15
  • @DavidCarlisle. I modified the code as follows { \renewcommand{\arraystretch}{1} \begin{array}{@{}>{\scriptstyle}c @{\thinspace\thinspace\thinspace}>{\scriptstyle}c@{}} #1 & #2 \\ #3 & #4 \end{array} }. @barbara beeton. I do not usually use \Bigl and \Bigr| because they do not dynamically adjust to match the size of their contents Oct 13, 2019 at 21:32

1 Answer 1

2

Note that there are several things in play here, firstly there is the white space within the array itself caused by the strut that is added in each line (so that arrays with capital letters have the same line height as one like this with lowercase, which gives the appearance of space above the array if it is all lower case. Then there is the behaviour of \left\right which (within limits set by \delimtershortfall and \delimiterfactor expands to cover the height and depth but is always vertically centred so you can not affect the two lengths that you show separately, if you increase the depth of the rules then the height also increases.

I suspect that here it is enough to just add a little more depth to the last row as shown in the second example.

enter image description here

\documentclass{book}

\usepackage{mathtools}
\show\arraystretch

\newcommand{\abs}[1]{\left| #1 \right|}
\newcommand{\matTwoByTwo}[4]{{% extra group
    \renewcommand{\arraystretch}{1}% this is the default anyway
    \begin{array}{@{\thinspace}c @{\thinspace\thinspace\thinspace}c@{\thinspace}}
        #1 & #2
        \\
        #3 & #4
    \end{array}%
}}

\newcommand{\matTwoByTwoB}[4]{{% extra group
    \begin{array}{@{\thinspace}c @{\thinspace\thinspace\thinspace}c@{\thinspace}}
        #1 & #2
        \\
        #3 & #4\\[2pt]
    \end{array}%
}}
\newcommand{\matTwoByTwoAbs}[4]{%
\abs{\matTwoByTwo{#1}{#2}{#3}{#4}}
}
\newcommand{\matTwoByTwoAbsB}[4]{%
\abs{\matTwoByTwoB{#1}{#2}{#3}{#4}}
}

\begin{document}

\begin{equation}
    \frac{\matTwoByTwoAbs{a_{4}}{a_{2}}{a_{3}}{a_{1}}}{a_{3}}
    \frac{\matTwoByTwoAbsB{a_{4}}{a_{2}}{a_{3}}{a_{1}}}{a_{3}}
\end{equation}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .