[Tex/LaTex] LaTeX – Writing Text In A Matrix

formattingmatricesr

I am trying to write text into a matrix to describe what an element at a particular row and column represents. The following is as far as I got ( after a few hours! ):

\begin{equation*}
P_{m,n} = 
\begin{pmatrix}
\text{description 1 - some text} & p_{1,2} \\
p_{2,1} & \text{description 2 - some more text}  \\
\end{pmatrix}
\end{equation*}

The text does not wrap and its size is too big relative to the rows and columns that do not have a description. Is it possible to write wrapped text in a matrix using LaTeX ( I am using Markdown in RStudio )? – if it is – what are the LaTeX commands?

Best Answer

You can put the text in a \parbox and specify both the text width and size. Also, I show a TABstack alternative in which the row baselineskip 22pt and column gap 3pt are easily specified.

\documentclass{article}
\usepackage{amsmath,tabstackengine}
\begin{document}
\begin{equation*}
P_{m,n} = 
\begin{pmatrix}
\parbox{.6in}{\raggedright\tiny description 1 - some text} & p_{1,2} \\
p_{2,1} & \parbox{.6in}{\raggedright\tiny description 2 - some more text}  \\
\end{pmatrix}
\end{equation*}

\begin{equation*}
\setstackgap{L}{22pt}
\setstacktabbedgap{3pt}
P_{m,n} = 
\parenMatrixstack{
\parbox{.6in}{\raggedright\tiny description 1 - some text} & p_{1,2} \\
p_{2,1} & \parbox{.6in}{\raggedright\tiny description 2 - some more text}
}
\end{equation*}
\end{document}

enter image description here