Math & Sciencehow to mark column number on a matrix

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
patiobarbecue
Posts: 13
Joined: Tue Oct 27, 2009 3:28 pm

how to mark column number on a matrix

Post by patiobarbecue »

I would like to indicate the column numbers on top of a matrix, how can I do it?

Currently, I use the top row to place column numbers, and it is not beautiful since the bracket[] enclose the top row. Ideally the column number should be outside the bracket.

Also the column number itself should be circled so as to standout from the numbers of the matrix itself. I used \ding{172} and \ding{173} from pifont package, however nothing shows up, though compilation was a success. any idea?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

php1ic
Posts: 192
Joined: Wed Jan 28, 2009 8:17 pm

how to mark column number on a matrix

Post by php1ic »

You could two smaller matrices inside a larger one like this:

Code: Select all

\[
\begin{matrix}

  \begin{matrix}
    a&b&c
  \end{matrix}\\

  \begin{bmatrix}
    1&2&3\\
    4&5&6
  \end{bmatrix}

\end{matrix}
\]
I don't know about the circle around the number, but I have seem a few post about similar things that were solved by using the pgf/TikZ packages.

EDIT: found the post I was thinking of
http://www.latex-community.org/forum/vi ... =44&t=6301
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to mark column number on a matrix

Post by localghost »

patiobarbecue wrote:I would like to indicate the column numbers on top of a matrix, how can I do it?

Currently, I use the top row to place column numbers, and it is not beautiful since the bracket[] enclose the top row. Ideally the column number should be outside the bracket.

Also the column number itself should be circled so as to standout from the numbers of the matrix itself. I used \ding{172} and \ding{173} from pifont package, however nothing shows up, though compilation was a success. any idea?
You should build a minimal working example (MWE) that shows the problem. You can also search the forum as well as the "Math mode" document for \bordermatrix.


Best regards and welcome to the board
Thorsten
patiobarbecue
Posts: 13
Joined: Tue Oct 27, 2009 3:28 pm

how to mark column number on a matrix

Post by patiobarbecue »

Unfortunately, using nested matrix doesn't lead to beautiful alignment. See the example below.

Code: Select all

\begin{matrix}
\begin{matrix}
1 & 2
\end{matrix}
\\
\begin{bmatrix}
-1 & 1\\
0 & 1
\end{bmatrix}
\end{matrix}
The manual for the \bordermatrix says it cannot be used together with AMS math, which disqualify it immediately since I mainly use AMS math. See page 21 of ftp://tug.ctan.org/pub/tex-archive/info ... thmode.pdf

Any other ideas?
torbjorn t.
Posts: 162
Joined: Wed Jun 17, 2009 10:18 pm

how to mark column number on a matrix

Post by torbjorn t. »

While not its intended use, perhaps you could use the Gauss-package. An example:

Code: Select all

\documentclass[a4paper,12pt]{article}
\usepackage{gauss}
\renewcommand{\colmultlabel}{}


\begin{document}
\[
\begin{gmatrix}[b]
a&b&c \\
d&e&f \\
g&h&i
\colops
\mult{0}{1}
\mult{1}{2}
\mult{2}{3}
\end{gmatrix}
\]
\end{document}
This does leave the problem of making the ring around the column number, for which I have no solution. Have you looked at the post mentioned above, where something like this was done with pgf/Tikz?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

how to mark column number on a matrix

Post by localghost »

patiobarbecue wrote:[...] The manual for the \bordermatrix says it cannot be used together with AMS math, which disqualify it immediately since I mainly use AMS math. [...]
The exact statement of the »Math mode« document at the referred place is slightly different.
Math mode (Section5 - Matrix, p. 21) wrote:The matrix environment macro cannot be used together with the AMS math package, it redefines this environment (see section 26.6 on page 56).
Hence there is no problem in using the \bordermatrix command even with the suggested enhancement to get the desired result.

Code: Select all

\documentclass[11pt,a4paper,english]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{amsmath}
\usepackage{pifont}

\makeatletter
\newif\if@borderstar
\def\bordermatrix{\@ifnextchar*{%
\@borderstartrue\@bordermatrix@i}{\@borderstarfalse\@bordermatrix@i*}%
}
\def\@bordermatrix@i*{\@ifnextchar[{\@bordermatrix@ii}{\@bordermatrix@ii[()]}}
\def\@bordermatrix@ii[#1]#2{%
\begingroup
\m@th\@tempdima8.75\p@\setbox\z@\vbox{%
\def\cr{\crcr\noalign{\kern 2\p@\global\let\cr\endline }}%
\ialign {$##$\hfil\kern 2\p@\kern\@tempdima & \thinspace %
\hfil $##$\hfil && \quad\hfil $##$\hfil\crcr\omit\strut %
\hfil\crcr\noalign{\kern -\baselineskip}#2\crcr\omit %
\strut\cr}}%
\setbox\tw@\vbox{\unvcopy\z@\global\setbox\@ne\lastbox}%
\setbox\tw@\hbox{\unhbox\@ne\unskip\global\setbox\@ne\lastbox}%
\setbox\tw@\hbox{%
$\kern\wd\@ne\kern -\@tempdima\left\@firstoftwo#1%
\if@borderstar\kern2pt\else\kern -\wd\@ne\fi%
\global\setbox\@ne\vbox{\box\@ne\if@borderstar\else\kern 2\p@\fi}%
\vcenter{\if@borderstar\else\kern -\ht\@ne\fi%
\unvbox\z@\kern-\if@borderstar2\fi\baselineskip}%
\if@borderstar\kern-2\@tempdima\kern2\p@\else\,\fi\right\@secondoftwo#1 $%
}\null \;\vbox{\kern\ht\@ne\box\tw@}%
\endgroup
}
\makeatother

\begin{document}
  \[
    \bordermatrix[{[]}]{%
      & \text{\ding{192}} & \text{\ding{193}} & \text{\ding{194}} \cr
      & 1 & 1 & 0 \cr
      & 1 & 1 & 0 \cr
      & 1 & 1 & 0 \cr
      & 1 & 0 & 1 \cr
      & 1 & 0 & 1 \cr
      & 1 & 0 & 1
    }
  \]
\end{document}
The code is taken from another thread [1]. I supplemented it with the amsmath package and the pifont font package from PSNFSS.

[1] View topic: Bmatrix Column Headings
Post Reply