6

I am trying to TeX a transition matrix for a Markov process and I want to be consistent with our textbook and label the columns and rows. I found \kbordermatrix and that let me produce:

    \[\kbordermatrix{
                    &L&M&C  \cr
            L& .94 &  .02  & .01    \cr
            M& .05  &  .96 &  .04   \cr
            C& .01 & .02 & .95      \cr
            }\]

But I'd like to add another label that spans the last three columns that says Current State (and is underline) and I'd like a way to label the the last three rows with Next State.

Is there an easy way to do this?

Herr K.
  • 17,946
  • 4
  • 61
  • 118
Megan
  • 61
  • 3
    Welcome to TeX.sx! Usually, we don't put a greeting or a “thank you” in our posts. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Accepting and upvoting answers is the preferred way here to say “thank you” to users who helped you. An image of the desired output would be a great help. – masu Nov 22 '13 at 19:01
  • potentially useful: http://tex.stackexchange.com/q/130184/18228, http://tex.stackexchange.com/q/40/18228, http://tex.stackexchange.com/q/109054/18228, http://tex.stackexchange.com/a/48597/18228, – Herr K. Nov 22 '13 at 19:58

2 Answers2

3

It's quite an ugly solution, but it's the closest I can get:

\documentclass{article}
\usepackage{kbordermatrix}
\usepackage{graphicx}
\begin{document}

\begin{tabular}{c@{}c@{}}
    & \mbox{\hspace{6mm}Current State} \\ 

    \parbox[c][17mm][t]{3mm}{\rotatebox{90}{Next State}} &
    $ \kbordermatrix{
      & L   & M   & C   \cr
    L & .94 & .02 & .01 \cr
    M & .05 & .96 & .04 \cr
    C & .01 & .02 & .95 \cr
    } $ \\ 
\end{tabular}

\end{document}

This results in:

enter image description here

The 6mm is used to position the 'Current State'

The 17mm is used to position the 'Next State'

The 3mm is the space between 'Next State' and the matrix

1

Here is a solution with {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\begin{NiceTabular}{c@{\;}cccc}
& & \Block{1-3}{Current State} \\ 
  &   & L   & M   & C   \\
\Block{3-1}{\rotate Next State} 
  & L & .94 & .02 & .01 \\
  & M & .05 & .96 & .04 \\
  & C & .01 & .02 & .95 \\
\CodeAfter \SubMatrix[{3-3}{5-5}]
\end{NiceTabular}
\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes).

Output of the above code

F. Pantigny
  • 40,250