PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : tikz: dynamischer Rahmen um Flowchart



Barny.G
26-01-2012, 18:13
Hallo liebe Gemeinde,

nun habe ich endlich einen schönen(?) Flowchart mit tikz gebastelt und ihn auch mit einem Rahmen versehen. (siehe Anhang und Code im Folgenden)


\documentclass{article}
\usepackage{geometry}
\geometry{a5paper,left=35mm,right=28mm, top=25mm, bottom=27mm}
\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc}

\begin{document}
\pagestyle{empty}
% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=red!15, text width=4.5em, text badly centered, node distance=15ex, inner sep=0pt]
%\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{block} = [rectangle, draw, fill=blue!25, node distance=15ex, text centered, rounded corners, text width=25ex, minimum height=5ex]
\tikzstyle{block2} = [rectangle, draw, fill=blue!15, node distance=15ex, text centered, rounded corners, text width=25ex, minimum height=5ex]
\tikzstyle{line} = [draw, -latex]
%\tikzstyle{cloud} = [draw, ellipse,fill=green!20, node distance=3cm, minimum height=2em]
\tikzstyle{cloud} = [draw, rectangle,fill=green!20, node distance=25ex, minimum height=5ex, rounded corners]

\noindent
\begin{tikzpicture}[node distance = 8ex, auto, scale=1.0]
\node [block2, node distance = 64ex] (init2) {Initialisierung mit $\boldsymbol{J}_i, \rho_i$};
\node [block2, below of=init2] (JTJ) {Eigenwerte und Ei\-gen\-vek\-to\-ren von $\boldsymbol{J}_i^\top \boldsymbol{J}_i$ berechnen};
\node [decision, below of=JTJ, node distance = 18ex] (TestRho) {$r\left(0\right) > \rho_i$};
\node [block2, below of=TestRho] (CalcLambda) {Iteration von $\lambda_i$};
\node [block2, right of=TestRho, text width=12ex, node distance = 20ex] (Rho2) {$\rho_i=\frac{\rho_i}{2}$};

\path [line] (init2) -- (JTJ);
\path [line] (JTJ) -- (TestRho);
\path [line] (TestRho) -- node {ja} (CalcLambda);
\path [line] (TestRho) -- node {nein} (Rho2);
\path [line] (JTJ) -- (TestRho) coordinate[midway] (mid);
\path [line] (Rho2) |- (mid);

%Rahmen
\draw [dashed, red!30!green!40!blue] ($(init2)+(-18ex,6ex)$) -- ($(CalcLambda)+(-18ex,-6ex)$)
-- ($(CalcLambda)+(29ex,-6ex)$)
-- ($(init2)+(29ex,6ex)$)
-- ($(init2)+(-18ex,6ex)$) coordinate[midway] (mid2);
\draw [red!30!green!40!blue] ($(mid2)+(0ex,2ex)$) node{Hebden-Verfahren};

\end{tikzpicture}
\end{document}

Nun möchte ich das Ding aber gern frei skalierbar haben und der zugegebener Maßen mit der Axt gezimmerte Rahmen macht da nicht so ganz mit. Was könnte ich da tun um einen relativen Bezug zu (irgendeinem) Element herzustellen?

Viele Grüße

Thomas

bobmalaria
26-01-2012, 19:16
hi,

schau dir mal die fitting library, abschnitt 34 im pgfmanual.pdf an. damit kann man um nodes einen rahmen bzw auch eine hintergrund definieren. das sollte genau das sein wonach du suchst.

gruss

Barny.G
26-01-2012, 19:47
Hallo bobmalaria,

immer noch in England? :)

Der Hinweis mit dem manual war ziemlich gut - jedoch macht die schöne Box ein Skalieren auf 2.0 nicht mit. Keine Ahnung warum.

Hier noch einmal der code zum nachvollziehen:

\documentclass{article}
\usepackage{geometry}
\geometry{a3paper,left=35mm,right=28mm, top=25mm, bottom=27mm}

\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc,fit }

\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=red!15, text width=4.5em, text badly centered, node distance=15ex, inner sep=0pt]
%\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{block} = [rectangle, draw, fill=blue!25, node distance=15ex, text centered, rounded corners, text width=25ex, minimum height=5ex]
\tikzstyle{block2} = [rectangle, draw, fill=blue!15, node distance=15ex, text centered, rounded corners, text width=25ex, minimum height=5ex]
\tikzstyle{line} = [draw, -latex]
%\tikzstyle{cloud} = [draw, ellipse,fill=green!20, node distance=3cm, minimum height=2em]
\tikzstyle{cloud} = [draw, rectangle,fill=green!20, node distance=25ex, minimum height=5ex, rounded corners]

\noindent
\begin{tikzpicture}[node distance = 8ex, auto, scale=1.0]

% Hebden-Verfahren
\node [block2, node distance = 64ex] (init2) {Initialisierung mit $\boldsymbol{J}_i, \rho_i$};
\node [block2, below of=init2] (JTJ) {Eigenwerte und Ei\-gen\-vek\-to\-ren von $\boldsymbol{J}_i^\top \boldsymbol{J}_i$ berechnen};
\node [decision, below of=JTJ, node distance = 18ex] (TestRho) {$r\left(0\right) > \rho_i$};
\node [block2, below of=TestRho] (CalcLambda) {Iteration von $\lambda_i$};
\node [block2, right of=TestRho, text width=12ex, node distance = 20ex] (Rho2) {$\rho_i=\frac{\rho_i}{2}$};

\path [line] (init2) -- (JTJ);
\path [line] (JTJ) -- (TestRho);
\path [line] (TestRho) -- node {ja} (CalcLambda);
\path [line] (TestRho) -- node {nein} (Rho2);
\path [line] (JTJ) -- (TestRho) coordinate[midway] (mid);
\path [line] (Rho2) |- (mid);

%Rahmen um Hebden nun mit nodes...
\node[draw=red!30!green!40!blue, dashed, fit=(init2) (JTJ) (TestRho) (CalcLambda) (Rho2)] (box) {};
\node[red!30!green!40!blue, above] at (box.north) {Hebden-Verfahren};

\end{tikzpicture}

\end{document}

Machst Du ja wieder "Nachtschicht"? ;)

Schöne Grüße

Thomas

bobmalaria
26-01-2012, 22:22
1) ja
2) nein
:)

versuche mal transform canvas={scale=2} anstatt nur ein scale=2. scale multipliziert koordinaten mit dem faktor. das scheint mit der positioning library nicht richtig hinzuhauen. eventuell ein bug, eventuell sind wir beide blind. :rolleyes:

gruss

Barny.G
27-01-2012, 08:54
Hallo und moin moin,

also das mit dem "canvas" funktioniert bei mir irgendwie nicht richtig. Habe ich es auch richtig in den Code eingebaut?


\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc,fit }
\begin{tikzpicture}[node distance = 8ex, auto, canvas={scale=0.5}]


Es wird der Fehler:

! Pckage pgfkeys Error: I do not know the key '/tikz/canvas' and I am going to ignore it.

gemeldet. Im Netz habe ich schon geschaut und da wird auch nicht auf ein extra Paket hingewiesen...

Hast Du noch eine Idee?

Schöne Grüße

Thomas

bobmalaria
27-01-2012, 09:52
mein fehler, ich sollte die tags verwenden


transform canvas={scale=2}

du kannst das also option beim tikzpicture mitgeben, dann wird alles, inkl schrift und rahmen usw 2x so gross

Barny.G
27-01-2012, 10:38
Hallo und moinmoin,

jetzt funktioniert das schon mal ganz toll. Danke!! Auch die Schriften sind wunderbar skaliert - kann man nicht meckern. :D

Leider gibt es in meinem file immer noch ein Problem:

die Zeichnung wird durch das transform irgendwie nach links vom Blatt herunter verschoben. Muß ich da nun einen uneleganten OffSet einbauen? Schließen sich vielleicht Deiner Erfahrung nach Pakete aus?

Die Beispiele, die ich nun im Netz gefunden haben scheinen gut damit zurecht zu kommen (ohne OffSet) mache ich da irgendwie einen Fehler? (ggf. mit absoluten Werten?)

Ich poste mal im Anschluß den ganzen code, falls es Dir was nützt :o

Viele Grüße

Thomas

--------------------------------

\documentclass{article}
\usepackage{geometry}
\geometry{a3paper,left=35mm,right=28mm, top=25mm, bottom=27mm}

\usepackage[latin1]{inputenc}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,calc,fit }

\begin{document}
\pagestyle{empty}


% Define block styles
\tikzstyle{decision} = [diamond, draw, fill=red!15, text width=4.5em, text badly centered, node distance=15ex, inner sep=0pt]
%\tikzstyle{block} = [rectangle, draw, fill=blue!20, text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{block} = [rectangle, draw, fill=blue!25, node distance=15ex, text centered, rounded corners, text width=25ex, minimum height=5ex]
\tikzstyle{block2} = [rectangle, draw, fill=blue!15, node distance=15ex, text centered, rounded corners, text width=25ex, minimum height=5ex]
\tikzstyle{line} = [draw, -latex]
%\tikzstyle{cloud} = [draw, ellipse,fill=green!20, node distance=3cm, minimum height=2em]
\tikzstyle{cloud} = [draw, rectangle,fill=green!20, node distance=25ex, minimum height=5ex, rounded corners]

\noindent
\begin{tikzpicture}[node distance = 8ex, auto, transform canvas={scale=1.0}]scale=1.0]%transform canvas={scale=0.5}]
% Place nodes
\node [block] (init) {Modellinitialisierung mit $\widehat{\boldsymbol{x}}, \rho$};
\node [block, below of=init, node distance=10ex] (Gx) {$\begin{matrix} \boldsymbol{Gx}_i=\boldsymbol{d} - f\left(\widehat{\boldsymbol{x}}_i\right) \\
\boldsymbol{J}_i = \frac{\partial f_{i}}{\partial x_j}
\end{matrix}$};
\node [block, below of=Gx] (Lambda) {Berechnung des Langrange-Faktors $\lambda_i$ mit dem Hebden-Verfahren};
\node[left=15ex of Lambda] (dummy) {};
\node [cloud, above of=dummy, node distance=5ex] (Rho) {$\rho_i, \boldsymbol{J}_i$};
% \node [cloud, left of=dummy] (Hebden) {$\begin{matrix}
% \text{Hebden-Verfahren} \\
% \text{ggf. Anpassung $\rho$} \\
% \text{Berechnung des } \lambda
% \end{matrix}$};
\node [cloud, below of=dummy, node distance=5ex] (LambdaRho)
{$\begin{matrix}
\lambda_i \\
\text{ggf. } \rho_i
\end{matrix}$};

\node [block, below of=Lambda] (dx) {Berechnung des Modellupdates $d\widehat{\boldsymbol{x}}_i = f\left(\boldsymbol{J}_i,\lambda_i,\boldsymbol{I},\ boldsymbol{Gx}_i\right)$};
\node [block, below of=dx] (AGK) {$\mu$-Test mit dem Armijo-Goldstein-Kriterium $f\left(d\widehat{\boldsymbol{x}}_i, \boldsymbol{J}_i, \boldsymbol{Gx}_i\right)$};

\node [decision, below of=AGK] (decide) {$\mu_i < 0.25$};
\node [block, below of=decide] (update) {$\widehat{\boldsymbol{x}}_{i+1} = \widehat{\boldsymbol{x}}_i + d\widehat{\boldsymbol{x}}_i$};
\node [block, right of=decide, node distance=18ex, text width=8ex] (RhoUpdate) {$\rho_i = \frac{\rho_i}{2}$};
\node [decision, below of=update, node distance=15ex, text width=11ex] (Abbruchbed) {Abbruch\-bedingung erreicht?};
\node [cloud, below of=Abbruchbed, node distance=20ex] (Ende) {Ende};

\node [decision, right of=Abbruchbed, node distance=31ex] (MuGross) {$\mu_i > 0.75$};
\node [block, right of=RhoUpdate, node distance=13ex, text width=9ex] (RhoUpdate2) {$\rho_i = 2 \rho_i$};
%\node [block, right of=RhoUpdate2, node distance=15ex, text width=8ex] (RhoUpdate3) {$\rho = \rho$};

% Draw edges
\path [line] (init) -- (Gx); %
\path [line] (Gx) -- (Lambda) coordinate[midway] (between_Gx_Lambda);
\path [line] (Lambda) -- (Rho);
% \path [line] (Rho) -- (Hebden);
% \path [line] (Hebden) -- (LambdaRho);
\path [line] (LambdaRho) -- (Lambda);
\path [line] (Lambda) -- (dx);
\path [line] (dx) -- (AGK);
\path [line] (AGK) -- (decide);
\path [line] (decide) -- node {nein} (update);
\path [line] (decide) -- node {ja} (RhoUpdate);
%\path [line] (RhoUpdate) |- (Gx);

\path [line] (RhoUpdate) |- (between_Gx_Lambda);

\path [line] (update) -- (Abbruchbed);
\path [line] (Abbruchbed) -- node {ja} (Ende);
\path [line] (Abbruchbed) -- node {nein} (MuGross);
\path [line] (MuGross) -- node {ja} (RhoUpdate2);
\path [line] (RhoUpdate2) |- (Gx);
\path [line] (MuGross) --node{nein} ($(MuGross)+(13ex,0)$) |- (Gx);

% Hebden-Verfahren
\node [block2, left of=Gx, node distance = 64ex] (init2) {Initialisierung mit $\boldsymbol{J}_i, \rho_i$};
\node [block2, below of=init2] (JTJ) {Eigenwerte und Ei\-gen\-vek\-to\-ren von $\boldsymbol{J}_i^\top \boldsymbol{J}_i$ berechnen};
\node [decision, below of=JTJ, node distance = 18ex] (TestRho) {$r\left(0\right) > \rho_i$};
\node [block2, below of=TestRho] (CalcLambda) {Iteration von $\lambda_i$};
\node [block2, right of=TestRho, text width=12ex, node distance = 20ex] (Rho2) {$\rho_i=\frac{\rho_i}{2}$};

\path [line] (init2) -- (JTJ);
\path [line] (JTJ) -- (TestRho);
\path [line] (TestRho) -- node {ja} (CalcLambda);
\path [line] (TestRho) -- node {nein} (Rho2);
\path [line] (JTJ) -- (TestRho) coordinate[midway] (mid);
\path [line] (Rho2) |- (mid);

\path [line] (Rho) |- (init2);
\path [line] (CalcLambda) -| (LambdaRho) ;

%Rahmen um Hebden
\node[draw=red!30!green!40!blue, dashed, fit=(init2) (JTJ) (TestRho) (CalcLambda) (Rho2)] (box) {};
\node[red!30!green!40!blue, above] at (box.north) {Hebden-Verfahren};

\end{tikzpicture}

\end{document}

bobmalaria
27-01-2012, 13:55
hi,

in der anleitung steht, dass bei der skalierung gewisse informationen verloren gehen. darunter auch die koordinaten positionen. deshalb ist es nur mit enem xshift moeglich.


transform canvas={scale=1.0,xshift=.6\textwidth},

beachte auch das das skalieren auf diese weise die linien dicker macht eventuell ist es ratsam die grafik gleich in der richtigen groesse zuerstellen.

gruss

Barny.G
27-01-2012, 14:22
Hallo bobmalaria,

jetzt ist alles gelöst! Es funktioniert. (schade, dass es in diesem Forum keine Huldigungs-emoticons gibt) ;)

Das mit dem Vergrößern und den dickeren Linien ist schon OK, da ich den chart entweder in einer Dokumentation oder auf einem Poster brauche. Und bei Zweiterem dürfen die Linien ruhig bisschen dicker sein - kein Problem...

Danke-Danke!

Schöne Grüße nach merry old england!

Thomas

Barny.G
28-01-2012, 11:00
bitte auch mal hier

http://mrunix.de/forums/showthread.php?t=72610

schauen. Es gab da beim Implementieren in ein "normales" Tex-Dokument ein unerartetes Problem...

Beste Grüße

Thomas