Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to redraw a kernel scheme diagram for a university lecture note. This is how far I got:

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[magyar]{babel}

\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}


\begin{document}

\begin{tikzpicture}[font=\sffamily]
    \tikzstyle{title}=[rectangle]
    \tikzstyle{wrapper}=[anchor=west, draw]
    \tikzstyle{bigblock}=[rectangle, minimum width=10cm, minimum height=1cm, anchor=west, draw]
    \tikzstyle{Nbigblock}=[rectangle, minimum width=10cm, minimum height=1cm, anchor=north, draw]
    \tikzstyle{Sbigblock}=[rectangle, minimum width=10cm, minimum height=1cm, anchor=south, draw]
    \tikzstyle{medblock}=[rectangle, minimum width=6cm, minimum height=1cm, anchor=south, draw]
    \tikzstyle{smallblock}=[rectangle, minimum width=3cm, minimum height=1cm, anchor=west, draw]

    \node (kernel) [title] {Kernel};
    \node (syscalls) [bigblock, below=of kernel] {Rendszerhívások};
    \node (filesystems) [smallblock, below=of syscalls.west] {Fájlrendszerek};
    \node (networklayer) [smallblock, below=of filesystems] {Hálózati réteg};

    \node (processhandling) [title,below=of syscalls.east] {Processzkezelés};
    \node (scheduler) [smallblock, below=of processhandling] {Ütemező};
    \node (memhandling) [smallblock, below=of scheduler] {Memóriakezelés};
    \node (IPC) [smallblock, below=of memhandling] {IPC};

    \node (processhandlingwrapper) [wrapper, fit={(processhandling) (scheduler) (memhandling) (IPC)}] {};

    \node (periphhandling) [bigblock, below=of processhandlingwrapper.south east] {Perifériák kezelése};

    \node (kernelwrapper) [wrapper, fit={(kernel) (filesystems) (syscalls) (networklayer) (processhandling) (periphhandling)}] {};

    \node (hardver) [below=of kernelwrapper.south, Nbigblock] {Hardver};

    \node (syslibs) [above=of kernelwrapper, medblock] {Rendszerkönyvtárak};

    \node (usrprocesses) [above=of syslibs, Sbigblock] {Felhasználói processzek};
\end{tikzpicture}

\end{document}

On the left you can see the diagram I want to redraw using TikZ, on the right side is my approach, where you can see wrong positioning and the lack of arrows.

Kernel scheme Kernel scheme

Could you help me correct the positioning and draw the arrows to the right places? Thanks!

share|improve this question

2 Answers 2

up vote 4 down vote accepted

The reason why the positioning in your example doesn't work as expected, is that there is a difference in whether one specifies the anchor of a node before or after the relative position (e.g., below=of). Take this simple example:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[demo/.style={anchor=west,draw}]
\node (A) [draw] {lorem};
\node [below=of A.south east,demo] {ipsum};
\node [yshift=-2em,demo,below=of A.south east] {ipsum};
\end{tikzpicture}
\end{document}

enter image description here

As you can see, when the anchor is specified after the relative position (top "ipsum"), the result is what one might expect. The reason it doesn't work for the opposite case, is that the anchor is set automatically when you use something like below=of somenode. Hence, when your anchor=west parameter is before the positioning, it will be overwritten.

Below then is code that more or less reproduces your diagram. A little hackish, as there is some manually shifting of nodes. Also, the top and bottom node aren't as wide as kernelwrapper. You could simply increase the minimum width for those a little, I don't know of a better way.

I added the arrows as well. Not the prettiest way perhaps, Stefan's way might be better. Instead of shifting the start point of the arrow, I used the <node name>.<angle> syntax. Probably not the best for rectangular nodes, though it works.

\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[magyar]{babel}

\usepackage{tikz}
\usetikzlibrary{positioning,fit}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}


\begin{document}

\begin{tikzpicture}[font=\sffamily]
    \tikzstyle{title}=[rectangle]
    \tikzstyle{wrapper}=[anchor=west, draw]
    \tikzstyle{bigblock}=[rectangle,minimum width=10cm, minimum height=1cm, anchor=west, draw]
    \tikzstyle{Nbigblock}=[rectangle, minimum width=10cm, minimum height=1cm, anchor=north, draw]
    \tikzstyle{Sbigblock}=[rectangle, minimum width=10cm, minimum height=1cm, anchor=south, draw]
    \tikzstyle{medblock}=[rectangle, minimum width=6cm, minimum height=1cm, draw]
    \tikzstyle{smallblock}=[rectangle, minimum width=3cm, minimum height=1cm, anchor=west, draw,node distance=.2cm]

    \node (kernel) [title,below=of syslibs] {Kernel};
    \node (syscalls) [bigblock, below=of kernel] {Rendszerhívások};
    \node (filesystems) [below=of syscalls.south west,smallblock] {Fájlrendszerek};
    \node (networklayer) [smallblock, below right=of filesystems,anchor=north,yshift=-1cm] {Hálózati réteg};

    \node (processhandling) [title,below=of syscalls.south east,anchor=east,xshift=-2.5ex] {Processzkezelés};
    \node (scheduler) [smallblock, below=of processhandling] {Ütemező};
    \node (memhandling) [smallblock, below=of scheduler] {Memóriakezelés};
    \node (IPC) [smallblock, below=of memhandling] {IPC};

    \node (processhandlingwrapper) [wrapper, fit={(processhandling) (scheduler) (memhandling) (IPC)}] {};

    \node (periphhandling) [below=of processhandlingwrapper.south east,bigblock,anchor=east] {Perifériák kezelése};

    \node (kernelwrapper) [wrapper, fit={(kernel) (filesystems) (syscalls) (networklayer) (processhandling) (periphhandling)}] {};

    \node (hardver) [below=of kernelwrapper, Nbigblock] {Hardver};
    \node (usrprocesses) [Sbigblock,above=2cm of kernelwrapper] {Felhasználói processzek};
    \node (syslibs) [above=of kernelwrapper.north west, medblock,anchor=west] {Rendszerkönyvtárak};

    \begin{scope}[latex-latex]
        \draw (usrprocesses.350) -- (usrprocesses.350 |- processhandlingwrapper.north);
        \draw (syslibs) -- (syslibs |- usrprocesses.south);
        \draw (syslibs) -- (syslibs |- syscalls.north);
        \draw (filesystems) -- (filesystems |- syscalls.south);
        \draw (filesystems) -- (filesystems -| processhandlingwrapper.west);
        \draw (filesystems.240) -- (filesystems.240 |- periphhandling.north);
        \draw (networklayer) -- (networklayer -| processhandlingwrapper.west);
        \draw (networklayer.150) -- (networklayer.150 |- filesystems.south);
        \draw (networklayer.60) -- (networklayer.60 |- syscalls.south);
        \draw (networklayer) -- (networklayer |- periphhandling.north);
        \draw (hardver) -- (periphhandling);
    \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer

You could use

  • \draw with optional arrow argument, such as \draw[<->], perhaps define a style for it
  • specify the nodes with anchors such as syslibs.north for connection
  • use |- in node specifications to get orthogonal arrows
  • use xshift for shifting arrows horizontally

For example:

\tikzstyle{doublearrow}=[draw, thick, latex-latex] 
...
\draw[doublearrow] (syslibs.north)--(usrprocesses.south);
\draw[doublearrow] (syslibs.south) --(syscalls.north-|syslibs.south);
\draw[doublearrow] ([xshift=-1.5cm]syscalls.north) -- 
                   ([xshift=-1.5cm]usrprocesses.south-|syscalls);

drawing arrows

share|improve this answer
    
Thank you. I'm goint to use this for drawing the arrows. But what about the positioning of the nodes? I'd like to achieve more or less the same positioning seen on the original diagram. –  szantaii Nov 24 '11 at 10:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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