LaTeX - 在矩阵中编写文本。

问题描述 投票:0回答:1

我想把文字写进一个矩阵中,以描述某一行和某一列的元素代表什么。以下是我目前所得到的结果(经过几个小时!)。

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

文本没有包裹,而且相对于没有描述的行和列来说,它的大小太大。是否可以使用LaTeX在矩阵中写出包裹的文本(我在RStudio中使用Markdown)?- 如果可以,LaTeX的命令是什么?

r matrix formatting latex
1个回答
2
投票

你可以把文本放在 \parbox 并指定文本宽度和大小。 此外,我还展示了一个TABstack的替代方案,其中行基线跳过了 22pt 和柱隙 3pt 是很容易指定的.如果你使用Rmarkdown,无论如何,陈述公式可以使用$ ... $或$$...$更容易。

\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


1
投票

如果你正在使用Rmarkdown,无论如何说明公式可以b更容易使用$ ... $或$$...$。

$$P_{m,n} = \begin{pmatrix} description1 & p_{2,1}\\p_{1,2}\ & description2\end{pmatrix}$$

上边的是用你的Latex代码,没有文字。

enter image description here


1
投票

您可以使用以下组合 tabular\left \right 命令如下。

\documentclass{article}
\usepackage{array}
\begin{document}
$$
\left(
\begin{tabular}{m{2cm}<{\centering}m{2cm}<{\centering}}
description 1 - some text & $x$\\
$y$ & description 2 - some text
\end{tabular}
\right)
$$
\end{document}

enter image description here

这不是很优雅,但也许它接近你的愿望。此外,你可以调整列的宽度,而不是给出一个绝对长度。

© www.soinside.com 2019 - 2024. All rights reserved.