3

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?

7

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

  • Is there a way to make them stack together nicely? – simonzack May 31 '14 at 0:58
  • @simonzack I have updated the answer. – user11232 May 31 '14 at 1:17
  • Thanks that looks great, perhaps I haven't communicated well enough but what I was also after was some kind of 'top left of' 'top right of' positioning relative to a block when drawing multiple blocks, do you think this is possible? – simonzack May 31 '14 at 1:22
  • @simonzack It is possible but matrix approach is the easiest IMO. – user11232 May 31 '14 at 1:24
4

Here was my approach by doing it with relative positioning, thanks to Harish for all the help in making it possible!

\documentclass{standalone}
\usepackage{tikz}

\usetikzlibrary{matrix}
\begin{document}

% use text width & text height instead of minimum size, as that causes
% alignment issues, and since blocks require uniform sizes
\tikzstyle{tblock} = [matrix of nodes,ampersand replacement=\&,nodes={
    outer sep=0pt,text width=2em,inner ysep=1em,text centered
}]

% \tblock {input} {output} {machine}
\newcommand{\tblocktext}[3]{
    {#1} \& $\to$   \& {#2} \\
         \&  {#3}   \&      \\
}

\newcommand{\tblockoutline}[1]{
    \draw (#1-1-1.south west) |- (#1-1-3.north east) |- (#1-1-3.south west) |- (#1-2-2.south west) |- (#1-1-1.south west);
}

\tikzstyle{wblock} = [outer sep=0pt,text width=2em,inner ysep=0.5em,text centered,font=\footnotesize]

\newcommand{\wblockoutline}[1]{
    \draw (#1.south) -- (#1.north west) -- (#1.north east) -- (#1.south);
}

\begin{tikzpicture}

    \node(left) [tblock] {\tblocktext{C}{M}{M}};
    \tblockoutline{left};

    \node(mid) at (left-1-2.south east) [tblock,anchor=mid-1-1.north west] {\tblocktext{C}{M}{M}};
    \tblockoutline{mid};

    \node(right) at (mid-1-3.north west) [tblock,anchor=right-1-1.south west] {\tblocktext{C}{M}{M}};
    \tblockoutline{right};

    \node(bottom) at (mid-2-2.south) [wblock,anchor=north] {H \\};
    \wblockoutline{bottom};

\end{tikzpicture}

\end{document}

output of tombstone diagram with relative positioning

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.