在多行中使用 tikz

在多行中使用 tikz

我正在尝试在乳胶中重新创建下图:

在此处输入图片描述

现在,我对其中的一个没什么意见:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds}

\usepackage[utf8]{inputenc} %utf-8 encoding
\usepackage{amssymb} %math symbols

\begin{document}

\begin{frame}
\begin{tikzpicture}[align=center,node distance=1cm]
\tikzstyle{vertex}=[circle,draw=black]
\tikzstyle{fluct}=[dotted]

\node[vertex] (v0) {};
\node[vertex] (v1) [right of = v0] {};
\node[vertex] (v2) [right of = v1] {};
\node[vertex] (v3) [below of = v0] {};
\node[vertex] (v4) [right of = v3] {};
\node[vertex] (v5) [right of = v4] {};

\node () [above of = v1] {Una realización};

\path[every node] 
  (v0) edge [] (v1)
  (v0) edge [] (v3)
  (v1) edge [] (v4)
  (v1) edge [fluct] (v2)
  (v2) edge [] (v5)
  (v4) edge [fluct] (v5);
\end{tikzpicture}
\end{frame}
\end{document}

但不确定如何创建其余部分。我考虑将它们复制并粘贴到表中。但多行似乎不起作用,并出现编译错误:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds}

\usepackage[utf8]{inputenc} %utf-8 encoding
\usepackage{amssymb} %math symbols

\begin{document}

\begin{frame}
\begin{figure}

\begin{tabular}{cc}

\multirow{4}{*} {

\begin{tikzpicture}[align=center,node distance=1cm]
\tikzstyle{vertex}=[circle,draw=black]
\tikzstyle{fluct}=[dotted]

\node[vertex] (v0) {};
\node[vertex] (v1) [right of = v0] {};
\node[vertex] (v2) [right of = v1] {};
\node[vertex] (v3) [below of = v0] {};
\node[vertex] (v4) [right of = v3] {};
\node[vertex] (v5) [right of = v4] {};

\node () [above of = v1] {Una realización};

\path[every node] 
  (v0) edge [] (v1)
  (v0) edge [] (v3)
  (v1) edge [] (v4)
  (v1) edge [fluct] (v2)
  (v2) edge [] (v5)
  (v4) edge [fluct] (v5);
\end{tikzpicture}

}
\\
& a \\ & b \\ & c \\ & d
\end{tabular}
\end{figure}
\end{frame}
\end{document}

在一张图片中完成所有操作让我感到很尴尬,因为我必须再次手动编号节点。我该如何解决这个问题?

答案1

如果您想重复部分tikzpicture或全部,pics这是一个不错的选择。以下代码显示了如何使用它们。pic声明 A 来绘制原始图形,此图片用于tikzpictures分布在 a 中的几个图形中tabular,其中第一列是 a multirow

如您所见,arraypic 仅绘制了图形的一部分,可以通过labels在每幅特定图片中添加更多互连线来完成。由于pic可以命名,因此您稍后可以使用这些名称在它们之间绘制一些连接。

\documentclass{article}
\usepackage{multirow}
\usepackage{tikz}
\usetikzlibrary{arrows,backgrounds,matrix, positioning}

\usepackage[utf8]{inputenc} %utf-8 encoding
\usepackage{amssymb} %math symbols

\tikzset{
    vertex/.style={circle, fill=black},
    fluct/.style=dotted,
    array/.pic = {
        \foreach \i [count=\row] in {0,1}
            \foreach \j [count=\col] in {0,1,2,3}
                \node[vertex] (\row\col) at (\col,-\row) {};
        \draw (21)|-(13)|-(24)--(14);
        \draw (22)--(12);
    }
}
\begin{document}

\begin{tabular}{cc}

\multirow{4}{*}[-1cm]{%
\begin{tikzpicture}[remember picture]
\pic (A) {array};
\path (A11) -- (A14) node[midway,above=3mm] {Una realización};
\draw[fluct] (A13)--(A14);
\end{tikzpicture}}
&
\begin{tikzpicture}[remember picture]
\pic (B) {array};
\path (B11) -- (B21) node[midway,left=3mm] {Una realización};
\draw[fluct] (B21)--(B22);
\end{tikzpicture}
\\
&
\begin{tikzpicture}[remember picture]
\pic (C) {array};
\path (C11) -- (C21) node[midway,left=3mm] {Una realización};
\draw[fluct] (C22)--(C23);
\end{tikzpicture}
\\
&
\begin{tikzpicture}[remember picture]
\pic (D) {array};
\path (D11) -- (D21) node[midway,left=3mm] {Una realización};
\draw[fluct] (D21)--(D23);
\end{tikzpicture}
\\
&
\begin{tikzpicture}[remember picture]
\pic (E) {array};
\path (E11) -- (E21) node[midway,left=3mm] {Una realización};
\end{tikzpicture}
\end{tabular}

\tikz[remember picture, overlay] \draw[red,thick,->] (A12) to[out=30, in=60] (B13);
\end{document}

在此处输入图片描述

相关内容