4

How would I recreate this format with equation/align/pmatrix? Image of what i'm trying to recreate

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

The content is not important, I'm just trying to get the layout! I have got this far, but I am also recieving the error: "Package amsmath Error: Erroneous nesting of equation structures;(amsmath) trying to recover with `aligned'. \end{align}"

what I've got

Any advice? Thank you!

1
  • 1
    Welcome into the TeX.SE community. An advice: The align environment does not need the equation environment.
    – Sebastiano
    Aug 13, 2021 at 10:59

3 Answers 3

3

First version: I have used spalign package to have the vertical rule in the matrix. There are so many ways to create your image. I've inserted the fonts from the image that look like Times New Roman to me.

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

enter image description here

Second version: Peraphs this MWE it is more closer to the original image.

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

enter image description here

3
  • 1
    Thank you so much!! Im relatively new to latex and havent heard of the spalign package before - so this was incredibly useful!
    – user249034
    Aug 13, 2021 at 11:35
  • @user249034 Wait :-)...working in progress :-)
    – Sebastiano
    Aug 13, 2021 at 11:36
  • 1
    @user249034 I thank you for the green checkmark but encourage you to choose the better answer. So as well know all do not care about the votes, but rather that you learn and stay with us in this wonderful community. :-)
    – Sebastiano
    Aug 13, 2021 at 11:48
3
\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}

The output image is:

enter image description here

2
  • Hi, there are two commas in t_1=11 and \mathit{sex}=1 :-) (missed)
    – Sebastiano
    Aug 13, 2021 at 11:50
  • 1
    Thank you! I have fixed it. Aug 13, 2021 at 11:53
3

I propose this code, based on alignedat, and a hack for the vertical line:

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

enter image description here

4
  • It is also perfect :-). There are two commas in the first matrix. After in the text you do an edit: you separe the word "thiscode" :-)
    – Sebastiano
    Aug 13, 2021 at 12:07
  • I not understood the word "hack"=tagliare in Italian language :-) cut, cut off, trim, chop, slice, hack.
    – Sebastiano
    Aug 13, 2021 at 12:16
  • 1
    Thank you for warning me, my friend. I've fixed everything (I believe). I must say I was glad of the dirty hack, so I didn't even thought of checking my post. Fortunately, you did it for me… ;o)
    – Bernard
    Aug 13, 2021 at 12:16
  • 1
    I believe that ’hack’, originally, means in English ‘cut (with an axe)’, so it seems to be the smae initial meaning, appled to a code. In French, we have another word, in popular language, which conveys the same meaning: the verb ‘charcuter’, but I've never seen it used for a code.
    – Bernard
    Aug 13, 2021 at 12:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .