[Tex/LaTex] Drawing tombstone diagrams

diagrams

Whats a good way to draw tombstone diagrams (wiki)?

enter image description here

I've found this but it requires specifying the coordinates when they need to be stacked together: http://blog.sterex.de/2013/04/latex-macro-for-tombstone-diagrams/

Is there something more convenient?

Best Answer

One way is to use tikz matrix,

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes]
{
 C  & $\to$ &  M \\
    &  M    &    \\
  };
 \draw (m-1-1.south west) |- (m-1-3.north east) |- (m-2-2.north east) |- (m-2-2.south west) |- (m-1-1.south west);
\end{tikzpicture}
\end{document}

enter image description here

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\begin{tikzpicture}
\matrix (m) [matrix of nodes,%nodes={minimum width=1em,minimum height=1.7em}
            ]
{
 C  & $\to$ &  M  & & C & $\to$ & M\\
    &  M    & C & $\to$ & M & M    \\
    &       &   & M  & & |[font=\tiny,yshift=4pt]|H         \\
    &       &   & |[font=\tiny]|H                \\
  };
 \draw (m-1-1.south west) |- (m-1-3.north east) |- (m-2-2.north east) |- (m-2-2.south west) |- (m-1-1.south west);
\draw (m-2-2.south east) |- (m-2-5.north east) --(m-2-5.south east) -- (m-2-5.south west) |- (m-3-4.south west) |- (m-2-2.south east);
\draw (m-2-5.north west) |- (m-1-7.north east) |- (m-2-6.north east) |- (m-2-5.south east) |- (m-2-5.north west);
\draw (m-3-4.south east) -- (m-4-4.south) -- (m-3-4.south west);
\draw (m-2-6.south east) -- (m-3-6.south) -- (m-2-6.south west);
\end{tikzpicture}
\end{document}

enter image description here