我如何编写一个在顶部和底部都有索引的矩阵?\bordermatrix
似乎没有多个索引的选项。
答案1
使用的示例blkarray
包裹:
\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}
答案2
一个TikZ
基于的解决方案!通过评论敲击建议,可以使循环更简单:它对矩阵每个条目的foreach
名称的行/列进行迭代,并在边界索引中重复使用该数字。matrix of math nodes
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}
\begin{document}
\begin{align*}
P&=
\begin{tikzpicture}[baseline=-\the\dimexpr\fontdimen22\textfont2\relax ]
\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}
按照该策略,也可以在矩阵的左侧或右侧定义索引:
\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{tikz}
\usetikzlibrary{matrix,calc}
\begin{document}
\begin{align*}
P&=
\begin{tikzpicture}[baseline=-\the\dimexpr\fontdimen22\textfont2\relax ]
\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}
结果:
答案3
该软件包nicematrix
提供了可以轻松完成这些事情的工具。
\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}
答案4
\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} a\\b\\c\\d\\e \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*}