Tikz 定位边缘不正确

Tikz 定位边缘不正确

我正在尝试在 Tikz 中建模图表,但它不想像我希望的那样定位边缘。以下代码生成图表:

\documentclass[a4paper,12pt,oneside,openright]{book} %twoside
\usepackage{wrapfig}
\usepackage{pgfplots}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}

\begin{document}
\tikzstyle{block} = [rectangle, draw, text width=8em, text centered, minimum height=4em]
\tikzstyle{bigblock} = [rectangle, draw, text centered]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse, text width=4em, text centered, node distance=4cm, minimum height=2em]

\begin{wrapfigure}{r}{0.5\textwidth}
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
\node [bigblock] (host) {
    \begin{tikzpicture}
    \node [] (title) {Host-OS};
    \node [block, node distance=1cm, below of=title] (emu) {Gast-OS in Emulator};
    \node [block, below of=emu] (xmount) {xmount};
    \node [block, below of=xmount] (bt) {QEMU Blocktreiber};
    \node [block, below of=bt] (curl) {cURL};
    \end{tikzpicture}
};
\node [cloud, right of=emu] (user) {Benutzer};
\node [cloud, right of=curl] (ia) {Image Archive};
% Draw edges
\path [line] (emu) -- (xmount);
\path [line] (xmount) -- (bt);
\path [line] (bt) -- (curl);
\path [line] (curl) -- (ia);
\path [line] (user) -- (emu);
\end{tikzpicture}
\end{wrapfigure}
\end{document}

这张图片就是结果:

图表

答案1

永远不要将一个 tikzpicture 放入另一个 tikzpicture 中(除非您是专家)。请改用fit

\documentclass{article}
\usepackage{wrapfig}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,fit}

\tikzstyle{block} = [rectangle, draw, text width=8em, text centered, minimum height=4em]
\tikzstyle{bigblock} = [rectangle, draw, text centered]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, ellipse, text width=4em, text centered, node distance=4cm, minimum height=2em]
\begin{document}
\begin{wrapfigure}{r}{0.5\textwidth}
\begin{tikzpicture}[node distance = 2cm, auto]
% Place nodes
    \node [] (title) {Host-OS};
    \node [block, node distance=1cm, below of=title] (emu) {Gast-OS in Emulator};
    \node [block, below of=emu] (xmount) {xmount};
    \node [block, below of=xmount] (bt) {QEMU Blocktreiber};
    \node [block, below of=bt] (curl) {cURL};
\node[bigblock,fit=(title) (curl)] (host) {};
\node [cloud, right of=emu] (user) {Benutzer};
\node [cloud, right of=curl] (ia) {Image Archive};
% Draw edges
\path [line] (emu) -- (xmount);
\path [line] (xmount) -- (bt);
\path [line] (bt) -- (curl);
\path [line] (curl) -- (ia);
\path [line] (user) -- (emu);
\end{tikzpicture}
\end{wrapfigure}
\end{document}

在此处输入图片描述

相关内容