I want to emphasize a block structure in a matrix by both, vertical and horizontal lines. Since I am using bmatrix as matrix environment I had the issues as in How to shorten \hline in a matrix.
I very much liked the first solution mentioned there using booktabs, because it calculates vertical spacings in a nice fashion and centers the horizontal lines correctly (e.g. with 2 rows the middle of the equal sign before the matrix will exactly be at the same height as the line drawn by cmidrule).
However, I still want to add vertical lines, therefore I use [cc|cc] as optional argument. But then the vertical line is interrupted by the vertical line.
Is there an easy way out? As far as I could figure out, the clue about cmidrule is the trim option which I couldn't find for hline or cline.
\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs} % required for the first solution
%matrix environment redef
\makeatletter
\renewcommand*\env@matrix[1][*\c@MaxMatrixCols c]{%
\hskip -\arraycolsep
\let\@ifnextchar\new@ifnextchar
\array{#1}}
\makeatother
\begin{document}
\begin{equation*}
\begin{bmatrix}[c|c]
a & b\\ \cmidrule(lr){1-2}
c & d
\end{bmatrix}
\end{equation*}
\end{document}
Best Answer
If you want the horizontal and vertical lines to intersect, you can't use the rule-drawing macros of the
booktabs
package.Here's a solution that uses just a basic
array
environment. This solution is similar to the one given by @Alenanno in the posting you provided a link to; the main difference is that the@{}
directives have been replaced with@{\,}
.Addendum: If you need a bit of extra vertical separation between the rows, you could load the
array
package and issue the instruction\setlength\extrarowheight{1pt}
in the preamble. This may be particularly useful if the submatrices have diacritics (such as\bar{...}
) that would otherwise come too close to the\hline
, as is the case with\bar{d}
in the example below.