7

for my thesis i need to put some block diagrams in my LaTeX document. I was recommended to use TikZ for that.
This is the only sample code i could find.

Do you guys maybe have some tutorials / doc on that?

Especially i am interested in how to put graphical symbols into the boxes instead of text. And how to draw a dashed box around blocks.

Something like:

image

2

1 Answer 1

10

To put a drawing into a block, I advise you to create some macros with your drawings and put them in the nodes as in the example below

\documentclass[border=10]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}


\newcommand{\symbolA}{
\tikz \draw[red] (0,0)--(0,0.2)--(0.2,0.2)--(0.2,0.4)--(0.4,0.4);
}

\newcommand{\symbolB}{
\tikz[y={(0,-1)}] \draw[blue] (0,0)--(0,0.2)--(0.2,0.2)--(0.2,0.4)--(0.4,0.4);
}

\newcommand{\symbolC}{
\begin{tikzpicture}
\draw[fill=green] (0,0) circle (0.2cm);
\end{tikzpicture}
}

\begin{document}

\begin{tikzpicture}
\node[draw](A) at (0,0){\symbolA};
\node[draw, right=2em of A] (B) {\symbolB};
\node[draw, right=2em of B] (C) {\symbolC};
\draw[-latex] (A) -- (B);
\draw[-latex](B) -- (C);
\end{tikzpicture}

\end{document}

node With images

of course you can use it with the code you quote

\documentclass[border=10]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,shapes,arrows}


\newcommand{\symbolA}{
\tikz \draw[red] (0,0)--(0,0.2)--(0.2,0.2)--(0.2,0.4)--(0.4,0.4);
}

\newcommand{\symbolB}{
\tikz[y={(0,-1)}] \draw[blue] (0,0)--(0,0.2)--(0.2,0.2)--(0.2,0.4)--(0.4,0.4);
}

\newcommand{\symbolC}{
\begin{tikzpicture}
\draw[fill=green] (0,0) circle (0.2cm);
\end{tikzpicture}
}
\begin{document}

\tikzstyle{block} = [draw, fill=blue!20, rectangle, 
    minimum height=3em, minimum width=6em]
\tikzstyle{sum} = [draw, fill=blue!20, circle, node distance=1cm]
\tikzstyle{input} = [coordinate]
\tikzstyle{output} = [coordinate]
\tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

% The block diagram code is probably more verbose than necessary
\begin{tikzpicture}[auto, node distance=2cm,>=latex']
    % We start by placing the blocks
    \node [input, name=input] {};
    \node [sum, right of=input] (sum) {};
    \node [block, right of=sum] (controller) {\symbolA};
    \node [block, right of=controller, pin={[pinstyle]above:Disturbances},
            node distance=3cm] (system) {\symbolB};
    % We draw an edge between the controller and system block to 
    % calculate the coordinate u. We need it to place the measurement block. 
    \draw [->] (controller) -- node[name=u] {$u$} (system);
    \node [output, right of=system] (output) {};
    \node [block, below of=u] (measurements) {\symbolC};

    % Once the nodes are placed, connecting them is easy. 
    \draw [draw,->] (input) -- node {$r$} (sum);
    \draw [->] (sum) -- node {$e$} (controller);
    \draw [->] (system) -- node [name=y] {$y$}(output);
    \draw [->] (y) |- (measurements);
    \draw [->] (measurements) -| node[pos=0.99] {$-$} 
        node [near end] {$y_m$} (sum);
\end{tikzpicture}
\end{document}

node images 2

But you can also use the Schemabloc package: http://www.texample.net/tikz/examples/schemabloc/.

3
  • 2
    Nesting TikZ pictures is ... problematic. One could just draw the symbols on top of the nodes afterwards, or do it the other way around: draw the node under the symbol. May 10, 2012 at 9:13
  • 2
    hi Andrew, I don't understand "Nesting TikZ pictures is ... problematic. ", Can you explain, with an example
    – rpapa
    May 10, 2012 at 17:25
  • for \symbolC the syntax can be reduced to \tikz\draw..... rather than the existing -- is there some advantage to the existing syntax?
    – js bibra
    Jan 11 at 4:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .