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.

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

share|improve this question
4  
Here are two out of many relevant questions to get you started: Left and right align inside one tikz rectangular node and more advanced but probably more helpful (in fact might be a duplicate : Flow (or block) diagram tips?. Search for block diagrams on this site too. –  percusse May 9 '12 at 23:50
    
Look at thread How to create new node shapes? from pgf-users mail list. There, Mark Wibrow show some examples of new blocks with drawings inside. –  Ignasi May 10 '12 at 7:12
    
Thank you very much, that gets me started. –  bijan May 10 '12 at 11:23
add comment

1 Answer

up vote 7 down vote accepted

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/.

share|improve this answer
    
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. –  Loop Space May 10 '12 at 9:13
    
Thanks so much for your effort! –  bijan May 10 '12 at 11:27
    
hi Andrew, I don't understand "Nesting TikZ pictures is ... problematic. ", Can you explain, with an example –  rpapa May 10 '12 at 17:25
add comment

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.