Graphics, Figures & TablesHow to create an ergonomic diagram in tikz?

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
usr345
Posts: 37
Joined: Fri Apr 01, 2011 11:39 pm

How to create an ergonomic diagram in tikz?

Post by usr345 »

I am very interested in created ergonomic diagrams. But MS Visio is evil. Can someone help me to do this in tikZ?


Edit by localghost: Preferably no external links (see Board Rules). Attachments go onto the forum server where possible.
Attachments
ergonomic.png
ergonomic.png (6.64 KiB) Viewed 3661 times

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

sitex
Posts: 70
Joined: Sat May 09, 2009 12:37 pm

How to create an ergonomic diagram in tikz?

Post by sitex »

Hello,

I would begin by modifying the code for one of the examples located at
http://www.texample.net/tikz/examples/tag/diagrams/.

Tom
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

How to create an ergonomic diagram in tikz?

Post by localghost »

usr345 wrote:I am very interested in created ergonomic diagrams. But MS Visio is evil. Can someone help me to do this in tikZ?
It is possible with pgf/tikZ and some of its additional libraries.

My first idea was the following which gave me two errors and bad box warnings. It was simple and flexible, but didn't result in the output as shown in the picture.

Code: Select all

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,fit,positioning,shapes,shapes.callouts}

\begin{document}
  \begin{tikzpicture}[%
    shorten >=3pt,
    shorten <=3pt,
    node distance=5cm,
    note/.style={draw,fill=white,rectangle callout,minimum width=10em,minimum height=4ex},
    content/.style={draw,fill=white,ellipse,minimum width=10em,minimum height=4ex}
  ]
    \node[content]                                   (a) {Let's go to bed};
    \node[content]                                   (b) [right of=a]                     {said Vasya};
    \node[note,callout absolute pointer={(a.north)}] (c) [node distance=1.5cm,above of=a] {Direct speech\strut};
    \node[note,callout absolute pointer={(b.north)}] (d) [right of=c]                     {Author's words\strut};

    \path (a) edge (b);
    \begin{scope}[on background layer]
      \node[draw,fill=gray!25,fit=(a) (b) (c) (d)] {};
      \node[draw,fill=gray!10,fit=(a) (b)] {};
    \end{scope}
  \end{tikzpicture}
\end{document}
The errors concern the „callout shapes“ and the absolute pointers to another node*.

Code: Select all

! Undefined control sequence.
\pgf@sh@bg@rectangle callout ...f@sh@np@\pgf@test 
                                                  \noexpand \endcsname }\ede...
l.15 ...e=1.5cm,above of=a] {Direct speech\strut};
                                                  
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Undefined control sequence.
\pgf@sh@bg@rectangle callout ...f@sh@np@\pgf@test 
                                                  \noexpand \endcsname }\ede...
l.16 ...                   {Author's words\strut};
                                                  
The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
I was not able to find out the cause of the error because I didn't find any mistake in my code.

So here is another example that does exactly what the picture shows without any warnings or errors.

Code: Select all

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{backgrounds,calc,positioning,shapes,shapes.callouts}

\begin{document}
  \begin{tikzpicture}[%
    shorten >=3pt,
    shorten <=3pt,
    node distance=5cm,
    note/.style={draw,fill=white,rectangle callout,minimum width=10em,minimum height=4ex},
    content/.style={draw,fill=white,ellipse,minimum width=10em,minimum height=4ex}
  ]
    \node[content]                                   (a) {Let's go to bed};
    \node[content]                                   (b) [right of=a]                     {said Vasya};
    \node[note,callout relative pointer={(0,-0.75)}] (c) [node distance=1.5cm,above of=a] {Direct speech\strut};
    \node[note,callout relative pointer={(0,-0.75)}] (d) [right of=c]                     {Author's words\strut};

    \path (a) edge (b);
    \begin{scope}[on background layer]
      \draw[fill=gray!25] ($(c.north west)+(-20pt,15pt)$) rectangle ($(d.south east)+(20pt,-65pt)$);
      \draw[fill=gray!10] ($(a.south west)+(-20pt,-10pt)$) rectangle ($(b.north east)+(20pt,10pt)$);
    \end{scope}
  \end{tikzpicture}
\end{document}
The disadvantage is that some things are hard-coded thus have to be adapted manually in case of other changes. A picture of the result is attached.

*Perhaps you want to send a bug report to the package maintainer(s) if you can reproduce the error.


Thorsten
Attachments
The resulting output of the second example.
The resulting output of the second example.
ergonomic.png (8.97 KiB) Viewed 3619 times
Post Reply