我如何才能使用环境创建以下矩阵array
?我不知道
我得到的是
$$
\left[
\begin{array}{c|c|c|c}
\Pf_{AA} & \Pf_{AB} & \mathbf{0} & \Pf_{A\{\omega\}} \\
\hline
\mathbf{0} & \Pf_{BB} & \Pf_{BA} & \Pf_{B\{\omega\}} \\
\hline
\mathbf{0} & \mathbf{0} & \I & \mathbf{0} \\
\hline
\mathbf{0} & \mathbf{0} & \mathbf{0} & 1
\end{array}
\right]
$$
但现在我想标记行和列
答案1
bigdelim
和 的解决方案arydshln
:
\documentclass{book}
\usepackage{array, bigdelim}
\newcommand{\Pf}{\mathbf{P}}
\newcommand{\If}{\mathbf{I}}
\usepackage{arydshln}
\begin{document}
\[ \setlength{\extrarowheight}{3pt}
\begin{array}{@{}cc@{}*{3}{c:}c@{}c}
& & \multicolumn{1}{c}{A} & \multicolumn{1}{c}{B} &\multicolumn{1}{c}{ C} & \multicolumn{1}{c}{\{\omega\}} \\
A & \ldelim[{4.5}{0.8em} &\Pf_{AA} & \Pf_{AB} & \mathbf{0} & \Pf_{A\{\omega\}} & \rdelim]{4.5}{1em}\\[0.5ex]
\cdashline{3-6}
B & & \mathbf{0} & \Pf_{BB} & \Pf_{BA} & \Pf_{B\{\omega\}} \\[0.8ex]
\cdashline{3-6}
C & & \mathbf{0} & \mathbf{0} & & \mathbf{0} \\[0.5ex]
\cdashline{3-6}
\{\omega\} & & \mathbf{0} & \mathbf{0} & \mathbf{0} & 1
\end{array}
\]
\end{document}
答案2
您还可以使用新命令添加第一行/列,而不会干扰数组的其余部分。
\documentclass{article}
\usepackage{arydshln}
\begin{document}
\newcommand{\Pf}{\mathbf{P}}
\newcommand{\UP}[2]{\makebox[0pt]{\smash{\raisebox{1.5em}{$\phantom{#2}#1$}}}#2}
\newcommand{\LF}[1]{\makebox[0pt]{$#1$\hspace{4.5em}}}
\[\renewcommand{\arraystretch}{1.3}
\left[
\begin{array}{c@{}c:c:c:c}
\LF{A} & \UP{A}{\Pf_{AA}} & \UP{B}{\Pf_{AB}} & \UP{C}{\mathbf{0}} & \UP{\{\omega\}}{\Pf_{A\{\omega\}}} \\ \hdashline
\LF{B} & \mathbf{0} & \Pf_{BB} & \Pf_{BA} & \Pf_{B\{\omega\}} \\ \hdashline
\LF{C} & \mathbf{0} & \mathbf{0} & \mathbf{I} & \mathbf{0} \\ \hdashline
\LF{\{\omega\}} & \mathbf{0} & \mathbf{0} & \mathbf{0} & 1 \\
\end{array}\right]
\]
\end{document}
答案3
具有(≥ 6.6{bNiceArray}
的nicematrix
2022-02-16)。
\documentclass{book}
\usepackage{nicematrix,tikz}
\newcommand{\Pf}{\mathbf{P}}
\newcommand{\If}{\mathbf{I}}
\begin{document}
\[ \setlength{\extrarowheight}{3pt}
\NiceMatrixOptions
{
custom-line =
{
command = hdashedline,
letter = I ,
tikz = dashed ,
width = \pgflinewidth
}
}
\begin{bNiceArray}{cIcIcIc}[first-col,first-row,left-margin,right-margin=3pt]
& A & B & C & \{\omega\} \\
A & \Pf_{AA} & \Pf_{AB} & \mathbf{0} & \Pf_{A\{\omega\}} \\
\hdashedline
B & \mathbf{0} & \Pf_{BB} & \Pf_{BA} & \Pf_{B\{\omega\}} \\
\hdashedline
C & \mathbf{0} & \mathbf{0} & & \mathbf{0} \\
\hdashedline
\{\omega\} & \mathbf{0} & \mathbf{0} & \mathbf{0} & 1
\end{bNiceArray}
\]
\end{document}
您需要多次编译(因为nicematrix
在后台使用 PGF/Tikz 节点)。