2

I'm trying to model a diagram in Tikz but it doesn't want to position the edges like I want it to. The following code produces the diagram:

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

This picture is the result:

Diagram

  • Welcome! Your snippet is unfortunately incomplete, missing documentclass, \documentclass{article}, \begin{document} and \end{document}. And did you invent the code yourself? If so, why do you put a tikzpicture into a tikzpicture? If not, what is its source? – marmot Jan 26 '18 at 23:34
  • The source for this is texwelt.de/wissen/fragen/1176/… (in german) I will update the snippet to a working minimal example... – Simon Jan 26 '18 at 23:40
  • Also, what do you want to change? We aren't mind-readers: you only say it doesn't work the way you'd like, but which way is that? – cfr Jan 26 '18 at 23:41
  • @cfr I always thought you were brewing a mind-reading potion in your nice cauldron ;-) – marmot Jan 26 '18 at 23:44
  • The edges are not placed as discribed in the code, for example the edge from vertice user ("Benutzer") should go to emu ("Gast-OS...") – Simon Jan 26 '18 at 23:46
3

One should never put a tikzpicture into another tikzpicture (unless you are an expert). Use fit instead.

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

enter image description here

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.