[texhax] how to typeset a matrix

Matthew Leingang leingang at math.harvard.edu
Fri Mar 16 02:09:56 CET 2007


On 3/15/07 5:40 PM, "Reinhard Kotucha" <reinhard.kotucha at web.de> wrote:

>>>>>> "kyanh" == kyanh  <kyanh at o2.pl> writes:
> 
>> Hello, I have searched through google but I could typeset the
>> following matrix:
>> http://img401.imageshack.us/img401/437/matrixxbr6.jpg
> 
>> [...]
> 
>> How can we typeset that matrix ?
> 
> I did not use LaTeX's picture environment for many years and I did not
> use TikZ/pgf before, hence the following code is very ugly:
> 
> __________________________________________________________________
> \documentclass{article}
> \usepackage{tikz}
> \begin{document}
> \unitlength=1mm
> 
> \newcommand{\southeastarrow}{\begin{picture}(0,0)(0,0)
>     \put(0,-10){\tikz\draw[->] (0mm,0mm) -- (14mm,-12mm);}
>   \end{picture}}
> 
> \begin{displaymath}
>   \left(\begin{array}{ccc}
>     \southeastarrow a & \southeastarrow b & c \\
>     d & e & f \\
>     g & h & i \\
>   \end{array}\right)
> \end{displaymath}
> 
> \end{document}
> __________________________________________________________________
> 
> 
> You will certainly find a better solution if you read the manuals more
> carefully than I did.  The TikZ/pgf manual is called pgfmanual.pgf.

Here is something quite similar.  I abandoned the matrix environment
altogether and had to place nodes in what looked like the same positions and
thus had to draw my delimeters "by hand".  It's not ideal (nor is it the
cleanest TikZ code) but it looks pretty good.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[baseline=1cm,xscale=0.75,yscale=0.75]
% main entries
\draw (0,2) node (a11) {$a_{11}$};
\draw (1,2) node (a12) {$a_{12}$};
\draw (2,2) node (a13) {$a_{13}$};
\draw (0,1) node (a21) {$a_{21}$};
\draw (1,1) node (a22) {$a_{22}$};
\draw (2,1) node (a23) {$a_{23}$};
\draw (0,0) node (a31) {$a_{31}$};
\draw (1,0) node (a32) {$a_{32}$};
\draw (2,0) node (a33) {$a_{33}$};
% vertical lines
\draw (-0.5,-0.5) -- (-0.5,2.5);
\draw (2.5,-0.5) -- (2.5,2.5);
% extra entries
\draw (3,2) node[gray] (a11') {$a_{11}$};
\draw (3,1) node[gray] (a21') {$a_{21}$};
\draw (3,0) node[gray] (a31') {$a_{31}$};
\draw (4,2) node[gray] (a12') {$a_{12}$};
\draw (4,1) node[gray] (a22') {$a_{22}$};
\draw (4,0) node[gray] (a32') {$a_{32}$};
% arrows
\draw[blue,->] (a11) -- (a22) -- (a33);
\draw[blue,->] (a12) -- (a23) -- (a31');
\draw[blue,->] (a13) -- (a21') -- (a32');
\draw[red,->] (a13) -- (a22) -- (a31);
\draw[red,->] (a11') -- (a23) -- (a32);
\draw[red,->] (a12') -- (a21') -- (a33);
\end{tikzpicture}
\end{document}

HTH,
Matt

-- 
Matthew Leingang
Preceptor in Mathematics
Harvard University

http://www.math.harvard.edu/~leingang/vCard.vcf




More information about the texhax mailing list