I want to draw a big matrix as an 8 by 8 to represent the combination of two HMMs. How do I go about it? 
- 45
-
3First, see https://tex.stackexchange.com/questions/59517/label-rows-of-a-matrix-by-characters . I would use tikzmarks and insert the "submatrixes" using tikz (see https://tex.stackexchange.com/questions/291843/highlight-matrix-cell-and-have-arrows-pointing-from-cell-with-text for example). – John Kormylo Sep 16 '23 at 01:05
-
5You should look into the nicematrix package, which is exactly designed for these kinds of things. – Willie Wong Sep 16 '23 at 03:15
2 Answers
Because you didn't specify what TeX format you want to use, I show you, what to do in plainTeX. There are macros \bordermatrix, \pmatrix and \multispan. The rest are almost TeX primitives.
$$
\def\mf #1 #2/#3 {\multispan4\kern#1pt\vtop to0pt{\null\vskip-.8\baselineskip
\hbox{$\displaystyle \pmatrix{\cr\hbox to5.5em{\hss#2\hss}\cr
\rm\hfil#3\cr\cr}$}\vss}}
\delcode`(=\delcode`[ \delcode`)=\delcode`]
\bordermatrix{ &s_1&s_2&s_3&s_4&s_5&s_6&s_7&s_8\cr
s_1 & \mf0 HMM/Data & 0 & 0 & 0 & 0 \cr
s_1 & & & & & 0 & 0 & 0 & 0 \cr
s_1 & & & & & 0 & 0 & 0 & 0 \cr
s_1 & & & & & 0 & 0 & 0 & 0 \cr
s_1 & 0 & 0 & 0 & 0 & \mf7 HMM/Noise \cr
s_1 & 0 & 0 & 0 & 0 \cr
s_1 & 0 & 0 & 0 & 0 \cr
s_1 & 0 & 0 & 0 & 0 \cr
}
$$
\bye
- 74,238
With {bNiceMatrix} of nicematrix.
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
$\begin{bNiceMatrix}%
[
margin ,
first-row , code-for-first-row = s_{\arabic{jCol}} ,
first-col , code-for-first-col = s_{\arabic{iRow}}
]
&&&&&&&& \
& \Block{4-4}{\text{HMM}{\text{Deta}}}
&&& &0&0&0&0\
& &&& &0&0&0&0\
& &&& &0&0&0&0\
& &&& &0&0&0&0\
& 0&0&0&0 & \Block{4-4}{\text{HMM}{\text{Noise}}} \
& 0&0&0&0 \
& 0&0&0&0 \
& 0&0&0&0 \
\CodeAfter
\SubMatrix[{1-1}{4-4}][extra-height=-1mm]
\SubMatrix[{5-5}{8-8}][extra-height=-1mm]
\end{bNiceMatrix}$
\end{document}
You need several compilations (because nicematrix uses PGF/TikZ nodes under the hood.
- 40,250

