1

How do we put a multi-line label in \bordermatrix without a dirty hack? I do not wish to use other matrix packages or blockarray type of environments. I simply wish to leave extra vertical space before the actual matrix brackets/parantheses start. My code is below with a snapshot of the current situation (0 and 1 are part of labels below "dry" and "rainy"):

\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}

matrix with bleeding label line

angie
  • 13
  • 3

2 Answers2

1

You can use nicematrix. There's room for improvement, but this is the idea.

\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}

enter image description here

egreg
  • 1,121,712
  • Thank you @egreg. I tried it but I had a very hard time trying to figure out the option clashes. Finally, I gave up on not using a dirty hack. Please see the one I posted. – angie Nov 02 '22 at 20:47
0

I used \noalign to raise the multi-line label, \stackengine (see Centering text in box) for IMO better linespacing compared to \substack and modified \bordermatrix (see bordermatrix with more space between rows when there are fractional elements) for spacing and removing brackets around the first matrix on the left.

\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}

the not so elaborate result

angie
  • 13
  • 3