3

I've just finished my first TikZ flowchart, and I have a couple of wished to improve it, but I can't seem to search my way to a solution. I would like do this in 2 colomns, with dashed a line between them. As you can see, theres one node, where the dashed line is intented to be. Is it possible to make a tabular or multicol, in a way where thats possible?

\documentclass{memoir}
\usepackage[latin1]{inputenc}
\usepackage[a4paper,vmargin={30mm,0mm},hmargin={0mm,0mm}]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows, shadows, calc}
\begin{document}
\pagestyle{empty}

\begin{center}
\tikzstyle{block} = [rectangle, draw, fill=gray!20, 
text width=8em, text centered, minimum height=4em, drop shadow]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, rectangle, rounded corners,fill=white!20, node distance=2cm,
minimum height=2em, drop shadow]

\begin{tikzpicture}[node distance = 2cm]
\node [block, xshift=12em] (post) {\large Postmoderne};
\node [block, xshift=-12em] (modern) {\large Moderne};
\node [cloud, below of=modern, node distance=7em, fill=red!20] (auto) {Øget             \emph{control}};
\node [cloud, below of=auto] (active) {\emph{Active learning} og positive udviklingsspiral};
\node [cloud, below of=active] (effect) {Mere effektivitet og positive emotioner};
\node [cloud, below of=post, node distance=4em, fill=red!20] (sparring) {Sparringssamarbejde};
\node [cloud, below of=sparring, node distance=3em] (support) {Øget social support};
\node [cloud, below of=support, node distance=11em] (kom) {Bedre kommunikation og gensidig respekt};
\node [cloud, below of=modern, node distance=24em, xshift=12em, fill=green!20] (res) {Resiliens hos medarbejder og organisation};


\path [line] (sparring) -- (support);
\path [line] (auto) -- (active);
\path [line] (active) -- (effect);
\path [line] (support) -- (active);
\path [line] (active) -- (kom);
\path [line] (kom) -- (res);
\path [line] (effect) -- (res);



\end{tikzpicture}
\end{center}

\end{document}

1 Answers1

2

Here's a first attempt.

  • I put your nodes into a matrix. This is like a LaTeX tabular environment, and makes the positioning of nodes in a grid very easy.

  • Unfortunately, unless I am mistaken, it is rather hard to draw lines between rows or columns in a TikZ matrix. You don't have column specifiers, for instance, like you do for tabular, so you can't write {c|c} to get two centred columns with a line between.

  • What I did was to draw a line from the top-centre point of the matrix to the bottom-centre point. This only looks right if the two columns are roughly the same width.
  • Update. I use shorten >=-3cm to shorten the bottom end of the dashed line by -3cm; that is, to lengthen it by 3cm. You can also write shorten <=-1 cm to extend the top end.

Code

\documentclass{memoir}
\usepackage[utf8x]{inputenc}
\usepackage[a4paper,vmargin={30mm,0mm},hmargin={0mm,0mm}]{geometry}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows, shadows, calc}
\usetikzlibrary{matrix}
\begin{document}
\pagestyle{empty}

\begin{center}
\tikzstyle{block} = [rectangle, draw, fill=gray!20, 
text width=8em, text centered, minimum height=4em, drop shadow]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [draw, rectangle, rounded corners,fill=white!20, node distance=2cm,
minimum height=2em, drop shadow]

\begin{tikzpicture}

\matrix (m) [column sep=2cm,row sep=2cm] {
  \node [block] (modern) {\large Moderne}; 
& \node [block] (post) {\large Postmoderne}; 
\\
& \node [cloud, fill=red!20] (sparring) {Sparringssamarbejde}; 
\\
  \node [cloud, fill=red!20] (auto) {Øget \emph{control}};
& \node [cloud] (support) {Øget social support}; 
\\
  \node [cloud] (active) {\emph{Active learning} og positive udviklingsspiral};
\\
  \node [cloud] (effect) {Mere effektivitet og positive emotioner};
& \node [cloud] (kom) {Bedre kommunikation og gensidig respekt};
\\
};

\draw[dashed, shorten >=-3cm] (m.north) -- (m.south);

\node [cloud, below of=effect, xshift=12em, fill=green!20] (res) {Resiliens hos medarbejder og organisation};

\path [line] (sparring) -- (support);
\path [line] (auto) -- (active);
\path [line] (active) -- (effect);
\path [line] (support) -- (active);
\path [line] (active) -- (kom);
\path [line] (kom) -- (res);
\path [line] (effect) -- (res);

\end{tikzpicture}
\end{center}

\end{document}

Output

enter image description here

David Carlisle
  • 757,742
  • Wow. That it exactly what I was looking for. Besides the fact that the dashed line cannot go all the way through. But maybe thats just the way? Are you aware of any other complete different way to compose the flowchart, so that it is possible? – Frederik Jun 07 '13 at 14:37
  • I extended the dashed line downwards by 3cm -- see my updated answer. Regarding the overall composition of the flowchart: this is the right way to do it when your nodes are roughly in a grid like this. If there is not such an obvious grid structure, then the matrix may start to lose its appeal. – John Wickerson Jun 07 '13 at 14:43
  • Extending with 'shorten' seems a bit weird? But thanks anyway. I think can go from here by searching for bg-colouring, arrowsize etc. One thing, though; How do you control which side the dashed line goes of the green box? Mines in front, but if i use 'your' code, it goes behind. :S – Frederik Jun 07 '13 at 15:42
  • PS. Good to see some foreigners digging into danish. ;) – Frederik Jun 07 '13 at 16:18
  • Tak :-). TikZ objects are drawn in the order they appear in your code. So to adjust the "z order" just swap the lines in the code. – John Wickerson Jun 07 '13 at 16:24
  • 1
    Be careful with shortening with negative amount. The bounding box will not get updated, so the line may extend in the following text. The “z order” can be changed with PGF layers or—very simple—with the backgrounds library. With the positioning library ([1], [2]) it is possible to do, say \node [cloud, below=1cm of m, fill=green!20] (res) {Resiliens hos medarbejder og organisation}; \begin{scope}[on background layer]\draw[dashed] (m.north) -- ([yshift=-1cm]res.south);\end{scope} – Qrrbrbirlbel Jun 07 '13 at 20:35
  • @Qrrbrbirlbel Thanks. Is \begin{scope}[on foo layer]...\end{scope} the same as \begin{pgfonlayer}{foo}...\end{pgfonlayer}? – John Wickerson Jun 07 '13 at 21:22
  • 1
    @JohnWickerson Yes and No. [on background layer] does indeed use the pgfonlayer environment but the backgrounds library also declares the background layer itself and sets the right order background, main. Though, it wouldn’t be that hard to change \pgfdeclarelayer so that it creates the right style. Just adding \tikzset{on #1 layer/.style={execute at begin scope={\pgfonlayer{#1}},execute at end scope={\endpgfonlayer}}} should do. – Qrrbrbirlbel Jun 07 '13 at 21:30