TeX - LaTeX Asked by ashpool on January 4, 2021
How can I write a matrix where there is an index at the top and also at the bottom? bordermatrix
doesn’t seem to have an option for multiple indices.
An example using the blkarray
package:
documentclass[12pt]{report}
usepackage{blkarray}
usepackage{amsmath}
begin{document}
[
begin{blockarray}{cccccc}
c_1 & c_2 & c_3 & c_4 & c_5
begin{block}{(ccccc)c}
1 & 1 & 1 & 1 & 1
0 & 1 & 0 & 0 & 1
0 & 0 & 1 & 0 & 1
0 & 0 & 0 & 1 & 1
0 & 0 & 0 & 0 & 1
end{block}
d_1 & d_2 & d_3 & d_4 & d_5
end{blockarray}
]
end{document}
Correct answer by Gonzalo Medina on January 4, 2021
A TikZ
based solution! By means of the comment percusse suggested, it is possible to make the foreach
loop simpler: it iterates on rows/columns of the names that matrix of math nodes
gives to each entry of the matrix and reuses that number also in the border index.
documentclass{article}
usepackage{amsmath,amssymb}
usepackage{tikz}
usetikzlibrary{matrix,calc}
begin{document}
begin{align*}
P&=
begin{tikzpicture}[baseline=-thedimexprfontdimen22textfont2relax ]
matrix(m)[matrix of math nodes,left delimiter=(,right delimiter=),inner sep=4pt,ampersand replacement=&]
{
x_1 & y_1 & s_1 & z_1
x_2 & y_2 & s_2 & z_2
x_3 & y_3 & s_3 & z_3
x_4 & y_4 & s_4 & z_4
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
foreach s in {1,2,...,4}{
% bottom index
node[red,shift=(m-4-s.south),yshift=-0.4cm](0,0) {$a_{s}$};
}
foreach n in {1,2,...,4}{
% top index
node[blue,shift=(m-1-n.north),yshift=0.4cm](0,0) {$b_{n}$} ;
}
end{tikzpicture}
end{align*}
end{document}
Following the strategy, it is also possible to define indices on the matrix's left or right side:
documentclass{article}
usepackage{amsmath,amssymb}
usepackage{tikz}
usetikzlibrary{matrix,calc}
begin{document}
begin{align*}
P&=
begin{tikzpicture}[baseline=-thedimexprfontdimen22textfont2relax ]
matrix(m)[matrix of math nodes,left delimiter=(,right delimiter=),inner sep=4pt,ampersand replacement=&]
{
x_1 & y_1 & s_1 & z_1
x_2 & y_2 & s_2 & z_2
x_3 & y_3 & s_3 & z_3
x_4 & y_4 & s_4 & z_4
};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
foreach s in {1,2,...,4}{
% bottom index
node[blue,shift=(m-4-s.south),yshift=-0.4cm,text height=1ex,](0,0) {$a_{s}$};
}
foreach n in {1,2,...,4}{
% right index
node[green!70!blue,shift=(m-n-4.west),xshift=1.5cm,text height=1ex,](0,0) {$b_{n}$} ;
}
end{tikzpicture}
end{align*}
end{document}
The result:
Answered by Claudio Fiandrino on January 4, 2021
Maybe this work
documentclass{article}
usepackage{amsmath}
usepackage{xcolor}
begin{document}
begin{align*}
begin{array}{c}
textcolor{blue}{ begin{array} {c@{hspace{13pt}}c@{hspace{13pt}}c@{hspace{13pt}}c@{hspace{13pt}}c@{hspace{13pt}}c@{hspace{-10pt}}}
y_1 & y_2 & y_3 & y_4 & y_5 & y_6
end{array}}[5pt]
begin{matrix}
x_1 x_2 x_3 x_4 x_5
end{matrix}quad
begin{bmatrix}
0.9 & 0 & 0 & 0 & 0 & 0
1 & 0.4 & 0.5 & 0 & 0 & 0
0 & 0 & 1 & 0 & 0 & 0
0 & 0 & 0.2 & 1 & 0 & 0
0 & 0 & 0 & 0.4 & 0.5 & 0.2
end{bmatrix}
end{array}
end{align*}
end{document}
Answered by juanuni on January 4, 2021
begin{align*} P=begin{array}{c} textcolor{blue}{ begin{array}{c@{hspace{13pt}}c@{hspace{13pt}}c@{hspace{13pt}}c@{hspace{13pt}}c@{hspace{13pt}}c}
y_1 & y_2 & y_3 & y_4 & y_5 & y_6 end{array}}[5pt] begin{array}{c} abcde end{array} begin{bmatrix}
0.9 & 0 & 0 & 0 & 0 & 0
1 & 0.4 & 0.5 & 0 & 0 & 0
0 & 0 & 1 & 0 & 0 & 0
0 & 0 & 0.2 & 1 & 0 & 0
0 & 0 & 0 & 0.4 & 0.5 & 0.2
end{bmatrix} end{array} end{align*}
Answered by Nobody-Knows-I-am-a-Dog on January 4, 2021
The package nicematrix
provides tools to do such things easily.
documentclass{article}
usepackage{nicematrix}
begin{document}
NiceMatrixOptions{code-for-first-row = color{red},
code-for-first-col = color{blue},
code-for-last-row = color{green},
code-for-last-col = color{magenta}}
$begin{pNiceArray}{cc|cc}[first-row,last-row=5,first-col,last-col,nullify-dots]
& C_1 & Cdots & & C_4 &
L_1 & a_{11} & a_{12} & a_{13} & a_{14} & L_1
Vdots & a_{21} & a_{22} & a_{23} & a_{24} & Vdots
hline
& a_{31} & a_{32} & a_{33} & a_{34} &
L_4 & a_{41} & a_{42} & a_{43} & a_{44} & L_4
& C_1 & Cdots & & C_4 &
end{pNiceArray}$
end{document}
Answered by F. Pantigny on January 4, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP