Math & Sciencelabels for a matrix

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

labels for a matrix

Post by NELLLY »

Hi
I need to have a matrix with [ ] as delimiters. For this I used the package amsmath

Code: Select all

\[P^{(1)}=\begin{bmatrix}
q_{11}^{(1)}&q_{12}^{(1)}&q_{13}^{(1)}\\
q_{21}^{(1)}&q_{22}^{(1)}&q_{23}^{(1)}\\
q_{31}^{(1)}&q_{32}^{(1)}&q_{33}^{(1)}
\end{bmatrix}\]
But I need to get labels for the rows and the columns taking the values (1) (2) (3) like the layout of the \bordermatrix command.
What can I do?

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

labels for a matrix

Post by gmedina »

Hi,

you can use the modification to \bordermatrix suggested in Math mode:

Code: Select all

\documentclass{book}
\usepackage{amsmath}

\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}

\[
  P^{(1)}=
  \bordermatrix[{[]}]{
  & (1) & (2) & (3) \cr
  (1) & q_{11}^{(1)}&q_{12}^{(1)}&q_{13}^{(1)}\cr
  (2) & q_{21}^{(1)}&q_{22}^{(1)}&q_{23}^{(1)}\cr
  (3) & q_{31}^{(1)}&q_{32}^{(1)}&q_{33}^{(1)}
}
\]

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
NELLLY
Posts: 113
Joined: Thu Nov 26, 2009 2:21 am

Re: labels for a matrix

Post by NELLLY »

This works perfectly. Thanks.
Post Reply