2

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}
  • Welcome to TeX.SE! I don't think the [bpv]matrix environments can take an optional environment of the form cc|cc. – Mico May 25 '15 at 13:46
  • @Mico: With the redefinition of the matrix environment as above it is possible to supply column options. – dba May 25 '15 at 14:41
  • @Mico: See here: (tex.stackexchange.com/questions/36757/…) – dba May 25 '15 at 14:56
  • Ah, it would have been easier to understand if you'd written \begin{bmatrix}[c|c]. At least that's what I think the intent is, since the body of the matrix contains just two columns, not four. – Mico May 25 '15 at 15:00
2

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 @{\,}.

enter image description here

\documentclass{article}
\begin{document}
$
\left[ \begin{array}{@{\,} c|c @{\,}}
  u & v\\      
  \hline
  w & x \\
\end{array} \right]
$
\end{document}

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.

enter image description here

\documentclass{article}
\usepackage{array} % for "\extrarowheight" macro
\begin{document}
$
\left[  \begin{array}{@{\,} c|c @{\,}}
  a & b\\      
  \hline
  c & \bar{d} \\
\end{array}  \right]
$
\setlength\extrarowheight{1pt}
$
\left[  \begin{array}{@{\,} c|c @{\,}}
  a & b\\      
  \hline
  c & \bar{d} \\
\end{array}  \right]
$
\end{document}
  • 1. So there's no way include extra height only at the columns seperated by hline with just one command (similar as booktabs' cmidrule does)? If you replace u by \bar{u} in your example the bar will almost touch the line. 2. Why is the above solution with array not the same as with the redefinition of the bmatrix environment (concerning the length of hline)? – dba May 25 '15 at 14:25
  • @user3733247 - I suppose \usepackage{array} and \setlength\extrarowheight{1pt} count as two commands, not one... Incidentally, since there's no \hline above u in my example, I don't think I understand your claim that "the bar [in \bar{u}] will almost touch the line". – Mico May 25 '15 at 14:29
  • @user3733247 - Regarding your second comment: I noted in a direct comment on your posting that it's not possible to redefine the bmatrix environment the way you propose to do, i.e., by adding an "optional" argument such as cc|cc. – Mico May 25 '15 at 14:31
  • Sorry, I meant w of course. And an optional argument seems possible as mentioned above a minute ago;) – dba May 25 '15 at 14:44
  • @user3733247 - Thanks, I now understand what the redefinition of \env@matrix does. Unfortunately, it doesn't seem to be flexible enough to permit a directive such as \begin{bmatrix}[@{}c|c@{}] without producing a bad collision between the brackets, the \hline, and the body of the matrix. I'd stick with the array solution given in my answer. – Mico May 25 '15 at 15:15

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.