绘制墓碑图

绘制墓碑图

绘制墓碑图的好方法是什么(维基百科)?

在此处输入图片描述

我找到了这个,但是当它们需要堆叠在一起时需要指定坐标:http://blog.sterex.de/2013/04/latex-macro-for-tombstone-diagrams/

还有更方便的吗?

答案1

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}

在此处输入图片描述

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

在此处输入图片描述

答案2

这是我采用相对定位的方法,感谢 Harish 提供的所有帮助!

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

输出具有相对定位的墓碑图

相关内容