我如何使用 equation/align/pmatrix 重新创建这种格式?
\begin{equation}
\begin{align}
P(t&=11 \\ t&=13 |sex&=1 \\ education &=1 )
\end{align} = \begin{pmatrix}
q_{11t} & q_{12t} & 0 & 0 & q_{15t} \\
q_{21t} & q_{22t} & q_{23t} & 0 & q_{25t} \\
0 & q_{32t} & q_{33t} & q_{34t} & q_{35t} \\
0 & 0 & q_{43t} & q_{44t} & q_{45t} \\
0 & 0 & 0 & 0 & 0
\end{pmatrix}
\label{fig:transition-intensity-matrix}
\end{equation}
内容并不重要,我只是想了解布局!我已经做到了这一点,但我还收到了错误:“软件包 amsmath 错误:方程结构嵌套错误;(amsmath) 尝试使用‘aligned’进行恢复。\end{align}”
有什么建议吗?谢谢!
答案1
第一个版本:我使用spalign
包在矩阵中设置垂直规则。有很多方法可以创建图像。我插入了图像中的字体,在我看来,这些字体看起来像 Times New Roman。
\documentclass[a4paper,12pt]{article}
\usepackage{newtxtext,newtxmath}
\usepackage{spalign}
\begin{document}
\[
\mathbf{\hat{P}}
\spalignaugmatn[l]{1}{{t_1=11,} {\mathit{sex}=1,};{t_2=13} {\mathit{education}=1}}
= \begin{pmatrix}
q_{11t} & q_{12t} & 0 & 0 & q_{15t} \\
q_{21t} & q_{22t} & q_{23t} & 0 & q_{25t} \\
0 & q_{32t} & q_{33t} & q_{34t} & q_{35t} \\
0 & 0 & q_{43t} & q_{44t} & q_{45t} \\
0 & 0 & 0 & 0 & 0
\end{pmatrix}
\label{fig:transition-intensity-matrix}
\]
\end{document}
第二版:关于这个 MWE,它更接近原始图像。
\documentclass[a4paper,12pt]{article}
\usepackage{mathtools,amssymb}
\begin{document}
\[\mathbf{\hat{P}}\biggl(\,\begin{aligned}
& t_1=11, \\
& t_2=13
\end{aligned}\, \Big\lvert \mkern5mu \begin{aligned}
& \mathit{sex}=1,\\
& \mathit{education}=1
\end{aligned}\,\biggr)=\begin{pmatrix}
q_{11t} & q_{12t} & 0 & 0 & q_{15t} \\
q_{21t} & q_{22t} & q_{23t} & 0 & q_{25t} \\
0 & q_{32t} & q_{33t} & q_{34t} & q_{35t} \\
0 & 0 & q_{43t} & q_{44t} & q_{45t} \\
0 & 0 & 0 & 0 & 0
\end{pmatrix}
\label{fig:transition-intensity-matrix} \]
\end{document}
答案2
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\mathbf{\hat{P}}\left(
\begin{array}{@{}l|l@{}}
t_1=11, & \mathit{sex}=1,\\
t_2=13 & \mathit{education}=1
\end{array}\right)
=
\begin{pmatrix}
q_{11t} & q_{12t} & 0 & 0 & q_{15t} \\
q_{21t} & q_{22t} & q_{23t} & 0 & q_{25t} \\
0 & q_{32t} & q_{33t} & q_{34t} & q_{35t} \\
0 & 0 & q_{43t} & q_{44t} & q_{45t} \\
0 & 0 & 0 & 0 & 0
\end{pmatrix}
\]
\end{document}
输出图像为:
答案3
我提出了这个基于 alignedat 的代码,以及一个针对垂直线的 hack:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\widehat{\mathbf{P}}\biggl(
\begin{alignedat}{3}t&=11, &\enspace &\smash{\rule[-3.3ex]{0.6pt}{5ex}}\enspace & \text{sex}&=1,\\[-0.5ex] %
t&=13 & & & \text{education} &=1
\end{alignedat}\biggr) = \begin{pmatrix}
q_{11t} & q_{12t} & 0 & 0 & q_{15t} \\
q_{21t} & q_{22t} & q_{23t} & 0 & q_{25t} \\
0 & q_{32t} & q_{33t} & q_{34t} & q_{35t} \\
0 & 0 & q_{43t} & q_{44t} & q_{45t} \\
0 & 0 & 0 & 0 & 0
\end{pmatrix}
\label{fig:transition-intensity-matrix}
\end{equation}.
\end{document}