# How to adjust vertical spacing in a matrix with an horizontal line?

I'm having trouble in balancing the vertical spacings in matrices which have a horizontal separation line, like in the following MWE :

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}
\raggedbottom
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage[table]{xcolor}
\definecolor{gray1}{RGB}{100,100,100}

\begin{document}

\setlength{\abovedisplayskip}{2ex}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayskip}{\abovedisplayskip}
\setlength{\belowdisplayshortskip}{\belowdisplayskip}
\setlength{\jot}{3ex}

\begin{equation}
M =\!
\arrayrulecolor{gray1}
\left[ \begin{array}{c|ccc}
A & 0 & 0 & E \\[2.1pt]  % To be adjusted
\hline \\[-12.5pt]  % To be adjusted
0 & B & 0 & 0 \\[1em]
0 & 0 & C & 0 \\[1em]
E & 0 & 0 & D
\end{array} \right]\!.
\end{equation}
Bla bla blabla:
\begin{equation}
M =\!
\arrayrulecolor{gray1}
\left[ \begin{array}{c|ccc}
A & 0 & 0 & E \\[1ex]  % To be adjusted
\hline \\  % To be adjusted
0 & B & 0 & 0 \\[1em]
0 & 0 & C & 0 \\[1em]
E & 0 & 0 & D
\end{array} \right]\!.
\end{equation}

\end{document}


Preview : In the first matrix, I adjusted the vertical spacing by eye only, using \\[2.1pt] and \\[-12.5pt], which is clearly a hack (and yet, the result isn't right).

I need the elements in the first and second lines to have the same vertical spacing as all the other lines below them (\\[1em]). How can I get that, instead of adjusting the vertical spacing by eye?

• I think this is best handled manually, although it's a pain. I suggest obtaining a good point scale; the pointruler tool is available on CTAN (easy to look up by that name). Print it out, preferably on acetate or some other stable transparent medium and measure away. Also, em isn't the best font-specific unit to use for vertical dimensions, since it's defined to be horizontal. ex (the x-height) is much better, although you'll have to adjust your mental concept. – barbara beeton Apr 22 '20 at 16:05

Is it like you want?

\documentclass[11pt,letterpaper,twoside]{book}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.1}
\raggedbottom
\usepackage{microtype}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathtools}
\usepackage[table]{xcolor}
\definecolor{gray1}{RGB}{100,100,100}

\begin{document}

\setlength{\abovedisplayskip}{2ex}
\setlength{\abovedisplayshortskip}{0pt}
\setlength{\belowdisplayskip}{\abovedisplayskip}
\setlength{\belowdisplayshortskip}{\belowdisplayskip}
\setlength{\jot}{3ex}

\begin{equation}
M =\!
\arrayrulecolor{gray1}
\left[ \begin{array}{c|ccc}
A & 0 & 0 & E \\[2.1pt] % To be adjusted
\hline \\[-12.5pt] % To be adjusted
0 & B & 0 & 0 \\[1em]
0 & 0 & C & 0 \\[1em]
E & 0 & 0 & D
\end{array} \right]\!.
\end{equation}
Bla bla blabla:
\begin{equation}
M =\!
\arrayrulecolor{gray1}
\left[ \begin{array}{c|ccc}
A & 0 & 0 & E \\[0.5ex] % To be adjusted
\hline \\[\dimexpr 1em-0.5ex-\arrayrulewidth-\jot] % To be adjusted
0 & B & 0 & 0 \\[1em]
0 & 0 & C & 0 \\[1em]
E & 0 & 0 & D
\end{array} \right]\!.
\end{equation}

\end{document} Edit: To have the horizontal libe vericalyy centred w.r.t. the rows above and below, use this code:

\begin{equation}
M =\!
\arrayrulecolor{gray1}
\left[ \begin{array}{c|ccc}
A & 0 & 0 & E \\[\dimexpr 0.5em-0.5\arrayrulewidth] % To be adjusted
\hline \\[\dimexpr 0.5em-0.5\arrayrulewidth-\jot] % To be adjusted
0 & B & 0 & 0 \\[1em]
0 & 0 & C & 0 \\[1em]
E & 0 & 0 & D
\end{array} \right]\!.
\end{equation} • That looks very good. Is it possible to put the horizontal line in the middle of that vertical space? It's currently a bit too high, relative to the elements A and B. – Cham Apr 22 '20 at 16:31
• @Cham: Please see my edit for a solution. – Bernard Apr 22 '20 at 18:49
• Marvelous! Is there a way to make this a macro declared in the preamble, so I could just type a small command on each sides of the \\ ? If so, what would you suggest? – Cham Apr 22 '20 at 19:34
• Define macro in the preamble \newcommand{\Chline}{\\[\dimexpr0.5#1]\hline \\[\dimexpr0.5#1-\jot-\arrayrulewidth]} ande use \Chline{some length} in the place of \\ \hline. – Bernard Apr 22 '20 at 20:17