Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I need to add some straight lines inside a matrix to indicate labeling of rows, like this:

screenshot

How do I do that?

share|improve this question
add comment

2 Answers 2

Leaders is optimal for this situation. amsmath provides \hdotsfor{<cols>} that draws a dotted leader across <cols> columns. It is also possible to overlay a row number by setting that specific row twice (once with \hdotsfor and once with a row number, say). I've also added \numberrowwithline{<cols>}{<stuff>} that draws a line (instead of dots) as a dash leader, and inserts <stuff> in the middle of <cols> columns. The default space on either side is \fboxsep.

The following is a modified example, taken from Herbert's mathmode document:

enter image description here

\documentclass{article}
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{amsmath}% http://ctan.org/pkg/amsmath

\newcommand{\numberrowwithline}[2]{%
  \multicolumn{#1}c%
    {\xleaders\hbox{-\kern-1pt}\hfill\kern\fboxsep%
        #2\hspace*{\fboxsep}%
        \xleaders\hbox{-\kern-1pt}\hfill\kern0pt%
        }%
}

\begin{document}
\begin{equation}
  \underline{A}=\left[\begin{array}{ccccccc}
    a_{11} & a_{12} & 0 & \ldots & \ldots & \ldots & 0 \\
    a_{21} & a_{22} & a_{23} & 0 & \ldots & \ldots & 0 \\
    0 & a_{32} & a_{33} & a_{34} & 0 & \ldots & 0 \\
    \hdotsfor{7} \\
    \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
    \hdotsfor{7} \\[-\normalbaselineskip]
        \multicolumn{7}{c}{\colorbox{white}{\ $R_n$\ }} \\
        \vdots & \vdots & \vdots & \vdots & \vdots & \vdots & \vdots \\
        \numberrowwithline{7}{R_i} \\
    0 & \ldots & 0 & a_{n-2,n-3} & a_{n-2,n-2} & a_{n-2,n-1} & 0 \\
    0 & \ldots & \ldots & 0 & q_{n-1,n-2} & a_{n-1,n-1} & a_{n-1,n} \\
    0 & \ldots & \ldots & \ldots & 0 & a_{n,n-1} & a_{nn}
  \end{array}\right]
\end{equation}
\end{document}

With the addition of xhfill you can go crazy with the colours and types of leaders. See the xhfill documentation for the different styles of lines as a sample.

share|improve this answer
add comment
  \multicolumn{3}{c}{\hrulefill R_2 \hrulefill}

if it is a 3 column array

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.