11

I indicate blocks in a matrix using \hline:

\documentclass{article}
\usepackage{amsmath}
\begin{document}
  \begin{equation*}
    \begin{bmatrix}
      a & b\\
      \hline
      c & d
    \end{bmatrix}
  \end{equation*}
\end{document}
\endinput

example image

However, for normal point sizes the document is generated in (11pt), the rule drawn crosses over the matrix borders. (For poster sizes, this is not the case.)

How can I shorten the rule on both sides so that this does not occur, while still preserving the vertical spacing provided by \hline?

Moriambar
  • 11,466
equaeghe
  • 5,976
  • 4
  • 30
  • 36

2 Answers2

12

The bmatrix environment and also the other matrix related ones use internally array, but do a backup after the left delimiter and before the right one. Therefore the rule made by \hline presents the problem you're facing.

There are technical reasons for using a backup rather than removing the intercolumn spacing at either end with @{}. There are two different solutions; one is to use booktabs and the other one is making a new environment for matrices with rule separators.

The first is more elegant, in my opinion. Both require you to specify the columns in some way.

\documentclass{article}
\usepackage{amsmath}

\usepackage{booktabs} % required for the first solution

% this is for the second solution; the argument is the number of columns
\newenvironment{lbmatrix}[1]
  {\left[\array{@{}*{#1}{c}@{}}}
  {\endarray\right]}

\begin{document}
\begin{equation*}
\begin{bmatrix}
  a & b\\
  \cmidrule(lr){1-2}
  c & d
\end{bmatrix}
\end{equation*}
\begin{equation*}
\begin{lbmatrix}{2}
  a & b\\
  \hline
  c & d
\end{lbmatrix}
\end{equation*}
\end{document}

enter image description here

David Carlisle
  • 757,742
egreg
  • 1,121,712
6

Try switching to array instead, apparently the bmatrix environment doesn't work well with horizontal lines (judging from what I've seen in other forums).

If you switch between \begin{array}{@{}cc@{}}, as suggested by daleif, \begin{array}{cc}, it will change the appearance.

matrices

\documentclass{article}
\usepackage{amsmath}
\begin{document}
    \[ \left[ \begin{array}{@{}cc@{}}
    a & b \\ \hline
    c & d
    \end{array} \right]
    %
    \left[ \begin{array}{cc}
    a & b \\ \hline
    c & d
    \end{array} \right]
    \]
\end{document}
Alenanno
  • 37,338