\bordermatrix 中的多行标签渗入矩阵

\bordermatrix 中的多行标签渗入矩阵

我们如何才能在不使用肮脏黑客的情况下放入多行标签\bordermatrix?我不希望使用其他矩阵包或blockarray环境类型。我只是希望在实际矩阵括号/圆括号开始之前留出额外的垂直空间。我的代码如下,其中包含当前情况的快照(0 和 1 是“干燥”和“下雨”下方标签的一部分):

\documentclass{article}
\usepackage{amsmath, amssymb,amsfonts,amsthm,mathtools} 
\usepackage{dsfont,mathbbol}
\usepackage[dvipsnames]{xcolor}

\begin{document}

\hspace*{0.46\textwidth} \textcolor{red}{Tomorrow}
%
\[\mathds{P} = 
\bordermatrix{ 
\text{\textcolor{red}{Today}}
& \substack{\text{\normalsize Dry} \\*[0.1\textfloatsep] \text{\normalsize 0}}  
& \substack{\text{\normalsize Rainy} \\*[0.1\textfloatsep] \text{\normalsize 1}} \cr
\text{\normalsize Dry } \hfill 0    & 0.8   & 0.2 \cr
\text{\normalsize Rainy } \hfill 1  & 0.6   & 0.4
}
\]
\end{document}

带出血标签线的矩阵

答案1

您可以使用nicematrix。还有改进的空间,但这就是想法。

\documentclass{article}
\usepackage{xcolor}
\usepackage{nicematrix}

\begin{document}

\[
P=\;\raisebox{1ex}{%
  \begin{NiceTabular}{@{} lccc @{}}[baseline=3]
  && \multicolumn{2}{c@{}}{\textcolor{red}{Tomorrow}} \\
  \multicolumn{2}{c}{\textcolor{red}{Today}} &
    \begin{tabular}{@{}c@{}} Dry \\ 0 \end{tabular} &
    \begin{tabular}{@{}c@{}} Rainy \\ 1 \end{tabular} \\
  Dry   & 0 & 0.8 & 0.2 \\
  Rainy & 1 & 0.6 & 0.4
  \CodeAfter\SubMatrix({3-3}{4-4})
  \end{NiceTabular}}
\]

\end{document}

在此处输入图片描述

答案2

我以前\noalign提出过多行标签, \stackengine(见文本框居中\substack)在我看来,与修改后的相比,行距更好\bordermatrix行距更好(见当有小数元素时,bordermatrix 的行间距更大) 用于分隔和删除左侧第一个矩阵周围的括号。

\documentclass{article}
\usepackage{amsmath, amssymb,amsfonts,amsthm,mathtools} 
\usepackage{dsfont,mathbbol}
\usepackage[dvipsnames]{xcolor}

% Made use of 
% https://tex.stackexchange.com/questions/271730/centering-text-in-box
\usepackage{stackengine}

% Made use of 
% https://tex.stackexchange.com/questions/125844/bordermatrix-with-more-space-between-rows-when-there-are-fractional-elements?rq=1
\usepackage{etoolbox}
\let\bbordermatrix\bordermatrix
\patchcmd{\bbordermatrix}{9.50}{4.75}{}{}
\patchcmd{\bbordermatrix}{\left(}{\left[}{}{}
\patchcmd{\bbordermatrix}{\right)}{\right]}{}{}

\let\bbbordermatrix\bordermatrix
\patchcmd{\bbbordermatrix}{9.50}{4.75}{}{}
\patchcmd{\bbbordermatrix}{\left(}{\; }{}{}
\patchcmd{\bbbordermatrix}{\right)}{}{}{}

\begin{document}

\begin{center}
\begin{tabular}{c@{}c}
& \textcolor{red}{Tomorrow}
\\*[0.2\textfloatsep]
\begin{minipage}{2\arraycolsep} 
{\begin{align*}
\mathds{P} = \; 
\bbbordermatrix{ 
\noalign{\vskip-0.75\baselineskip}\text{\textcolor{red}{Today}}
& \setstackEOL{\cr}\Longstack{\vphantom{0} \cr \vphantom{0}} \cr 
\text{\normalsize Dry} & \mathclap{0} \cr 
\text{\normalsize Rainy}    & \mathclap{1}
}   
\end{align*}}
\end{minipage}
&
\begin{minipage}{3\arraycolsep} 
{\begin{align*}
\bbordermatrix{ 
\noalign{\vskip-0.75\baselineskip} 
& \setstackEOL{\cr}\Longstack{Dry \cr 0}
& \setstackEOL{\cr}\Longstack{Rainy \cr 1} \cr 
& 0.8   & 0.2 \cr
& 0.6   & 0.4 
}
\end{align*}}%
\end{minipage}
\end{tabular}
\end{center}

\end{document}

不太复杂的结果

相关内容