Graphics, Figures & TablestikZ | Align Nodes in Flowchart

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

tikZ | Align Nodes in Flowchart

Post by usr345 »

I made a simple flowchart and have 2 questions:
  1. How to align the bottom nodes, so they are at the same horizontal level?
  2. How always to put "yes" and "no" nearby the 'if' icon, so they are 2mm from the edge of the nearby node?
Please, disregard the Russian text.

Code: Select all

\documentclass{article}
\usepackage[a4paper,landscape]{geometry}
\usepackage[cm]{fullpage}
\usepackage[utf8]{inputenc}
\usepackage[russian]{babel}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,backgrounds,calc,positioning}
\begin{document}
\begin{tikzpicture}[node distance = 1cm, auto]
\tikzset{
	line/.style = {draw},
	block/.style = {rectangle, draw, text width=3em, text centered, rounded corners, minimum height=2em},
	comment/.style = {rectangle, draw, text centered, rounded corners, minimum height=2em,fill=white},
	question/.style = {shape=chamfered rectangle, chamfered rectangle xsep=2cm, draw},
	terminator/.style = {shape=rounded rectangle, draw, inner sep=2mm},
}

\node[terminator] (node-1) {\parbox{4.1cm}{Определение платы\\ за коммунальные услуги\\ в многоквартирном доме}};

\node [comment, below = of node-1.south] (node-15) {В конце указаны пункты 307 ПП};

\begin{scope}[on background layer]
	\draw[fill=gray!10] ($(node-15.south west)+(-2mm,-2mm)$) rectangle ($(node-15.north east)+(2mm, 2mm)$);
\end{scope}

\path [line] (node-1) -- ($(node-15.north)+(0mm,+2mm)$);

\node [question, below = of node-15.south] (node-2) {ОПУ установлены?};

\path [line] ($(node-15.south)+(0mm,-2mm)$) -- (node-2);
\node [question, below = of node-2] (node-3) {ИПУ установлены?};
\node [block, below = of node-3.south] (node-4) {23};

\path [line] (node-3) -- node [near start] {да} (node-4);

\node [question, right = of node-4] (node-5) {Жилое помещение?};

\path [line] (node-3) -|  node [very near start] {нет} (node-5);
\node [right = of node-5, inner sep=0pt,minimum size=0pt] (node-5-1) {};

\node [block, below= of node-5.south] (node-6) {21};
\node [block, below = of node-5-1] (node-7) {20};

\path [line] (node-5) -- node [near start] {да} (node-6);
\path [line] (node-5) -| node [near start] {нет} (node-7);

\path [line] (node-2) -- node [near start] {да} (node-3);
\node [question, right = 10 cm of node-3] (node-8) {ИПУ установлены?};
\node [block, below = of node-8] (node-9) {16};

\path [line] (node-8) -- node [near start] {да} (node-9);

\node [question, right = of node-9, node distance=4cm] (node-10) {Жилое помещение?};
\node [right = of node-10, inner sep=0pt,minimum size=0pt] (node-10-1) {};

\path [line] (node-8) -| node [very near start] {нет} (node-10);

\node [block, below = of node-10] (node-11) {19};
\node [block, below = of node-10-1, node distance=3cm] (node-12) {20};

\path [line] (node-10) -- node [near start] {да} (node-11);
\path [line] (node-10) -| node [near start] {нет} (node-12);

\path [line] (node-2) -| node [pos=0.03] {нет} (node-8);

\node[coordinate, below = 3 cm of node-4] (node-13) {};

\path [line] (node-4) -- (node-13);
\path [line] (node-6) |- (node-13);
\path [line] (node-7) |- (node-13);
\path [line] (node-9) |- (node-13);
\path [line] (node-11) |- (node-13);
\path [line] (node-12) |- (node-13);

\node[terminator, below = of node-13, node distance=1.5cm] (node-14) {конец};

\path [line] (node-13) -- (node-14);

\end{tikzpicture}

\end{document}
Attachments
shag.png
shag.png (44.79 KiB) Viewed 12481 times
Last edited by usr345 on Fri Nov 11, 2011 1:05 pm, edited 2 times in total.

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

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

tikZ | Align Nodes in Flowchart

Post by localghost »

Your code is too complex and a bit confusing to discuss all the details. So I can only give some hints.

I suggest to drop the nodes "node-5-1" and "node-10-1" and position the nodes "node-7" and "node-11" directly. You can not only position nodes left, right, above or below others, but also e. g. »below right« with e. g. »node distance=1cm and 2cm«. You should proceed this way in any other cases you used these "helper" nodes. For details see the pgf/tikZ user guide.


Thorsten
usr345
Posts: 37
Joined: Fri Apr 01, 2011 11:39 pm

tikZ | Align Nodes in Flowchart

Post by usr345 »

I suggest to drop the nodes "node-5-1" and "node-10-1" and position the nodes "node-7" and "node-11" directly. You can not only position nodes left, right, above or below others, but also e. g. "below right"
I did as you said and got rid of the helper nodes:

Code: Select all

\node [question, below = of node-2] (node-3) {ИПУ установлены?};
\node [question, below right = 1.7cm of node-3] (node-5) {Жилое помещение?};
But is it possible to position the node relative to 2 nodes?

Code: Select all

\node [block, below= of node-5.south] (node-6) {21};
\node [block, below right= of node-5.south east, right = of node-6] (node-7) {20};
Cause it's very hard to calculate the millimeters. And now it is only to the right of node-6. "below right= of node-5.south east" declaration is ignored.
Attachments
shag1.png
shag1.png (14.99 KiB) Viewed 12457 times
usr345
Posts: 37
Joined: Fri Apr 01, 2011 11:39 pm

tikZ | Align Nodes in Flowchart

Post by usr345 »

I made it with the help of my Russian fellows.
http://dxdy.ru/post501913.html#p501913

Here is the solution:

Code: Select all

\node[block] at (node-5-1|-node-6) (node-7) {20};
node-5-1 is the helper node to the right of the fork. It's better to use a \coordinate instead of an empty \node there.

Or

Code: Select all

\node[block] at ([xshift=10mm] node-5.east|-node-6) (node-7) {20};
Without the helper node.
Post Reply