Überarbeitungsverlauf[Zurück]
Klicke auf Einblenden/Ausblenden von Überarbeitungen 4

16 Dez '13, 02:42

esdd's gravatar image

esdd
17.8k294257

Wie auch immer die Definition für „elegant“ in diesem Fall lautet, hier ist eine alternatives `Diamond`-Shape, das auf `diamond` basiert und sich nur in der Definition des `\outernortheast`-„Anchors“ von dieser unterscheided. unterscheidet. Ist `stretch Diamond to width` gesetzt, wird der in `/pgf/minimum width` gespeicherte Wert als fixe Rhombus-Breite interpretiert und der `aspect` dementsprechend gesetzt. Es wird dabei kein besonderer Test durchgeführt. Ist die Rhombus-Breite nur wenig größer als die Text-Breite inklusiver des doppelten `inner xsep`s, so kann es zu *sehr* hohen TikZ-Pictures oder zu Problem kommen, wenn der `aspect` eben gegen ∞ geht. Ist die `minimum width` sogar kleiner als die Breite, ist der eigentliche Rhombus einfach zu klein. Für `stretch Diamond to height` gilt Entsprechendes. ## Code \documentclass[margin=2mm,tikz]{standalone} \usetikzlibrary{shapes.geometric,chains,backgrounds} \makeatletter \newif\ifpgf@sh@Diamond@to@width \newif\ifpgf@sh@Diamond@to@height \pgfset{stretch Diamond to width/.is if=pgf@sh@Diamond@to@width} \pgfset{stretch Diamond to height/.is if=pgf@sh@Diamond@to@height} \pgfdeclareshape{Diamond}{% \savedanchor\outernortheast{% from tikzlibrary.shapes.geometric.code.tex with adaptions % % Calculate width and height of the inner rectangle % \pgf@xa=.5\wd\pgfnodeparttextbox% \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/inner xsep}}% \advance\pgf@xa by\pgf@xc% \pgf@ya=.5\ht\pgfnodeparttextbox% \advance\pgf@ya by.5\dp\pgfnodeparttextbox% \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/inner ysep}}% \advance\pgf@ya by\pgf@yc% % % Calculate width and height of diamond % \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}% \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}% \pgf@xb=.5\pgf@xb \pgf@yb=.5\pgf@yb \ifpgf@sh@Diamond@to@width \pgfmathsubtract@{\pgf@sys@tonumber\pgf@xb}{\pgf@sys@tonumber\pgf@xa}% \pgfmathdivide@{\pgfmathresult}{\pgf@sys@tonumber\pgf@ya}% \pgfsetshapeaspect{\pgfmathresult}% \else\ifpgf@sh@Diamond@to@height \pgfmathsubtract@{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@ya}% \pgfmathdivide@{\pgf@sys@tonumber\pgf@xa}{\pgfmathresult}% \pgfsetshapeaspect{\pgfmathresult}% \fi\fi \pgf@x=\pgf@xa% \advance\pgf@x by\pgfshapeaspect\pgf@ya% \pgf@y=\pgfshapeaspectinverse\pgf@xa% \advance\pgf@y by\pgf@ya% \ifpgf@sh@Diamond@to@width\else\ifpgf@sh@Diamond@to@height\else % % Check against minimum height/width % \ifdim\pgf@x<\pgf@xb% % yes, too small. Enlarge... \pgf@x=\pgf@xb% \fi% \ifdim\pgf@y<\pgf@yb% % yes, too small. Enlarge... \pgf@y=\pgf@yb% \fi% \fi\fi % % Add outer border % \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}% \advance\pgf@x by\pgf@xa% \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}% \advance\pgf@y by\pgf@ya% }% \savedanchor\text{% \pgf@x=-.5\wd\pgfnodeparttextbox% \pgf@y=-.5\ht\pgfnodeparttextbox% \advance\pgf@y by.5\dp\pgfnodeparttextbox% }% \inheritanchor[from=diamond]{text}% \inheritanchor[from=diamond]{center}% \inheritanchor[from=diamond]{mid}% \inheritanchor[from=diamond]{base}% \inheritanchor[from=diamond]{north}% \inheritanchor[from=diamond]{south}% \inheritanchor[from=diamond]{west}% \inheritanchor[from=diamond]{east}% \inheritanchor[from=diamond]{north east}% \inheritanchor[from=diamond]{south east}% \inheritanchor[from=diamond]{north west}% \inheritanchor[from=diamond]{south west}% \inheritanchorborder[from=diamond]% \inheritbackgroundpath[from=diamond]} \makeatother \tikzset{decision/.style={draw,Diamond,text width=+3cm,align=center}} \newcommand*\auxA[2]{% fixed inner seps \draw[dashed] ([shift={(-.3333em,-.3333em-#2\baselineskip)}]#1.text) rectangle ([shift={(-.3333em,-.3333em-#2\baselineskip)}, rotate around=180:(#1.center)]#1.text);} \begin{document} \begin{tikzpicture}[gridded,start chain=going below, node distance=+0pt, nodes={on chain}, stretch Diamond to width, decision/.append style={minimum width=+5cm}] \node[decision] (n1) {Mein Text}; \node[decision] (n2) {Hier sollte ein mehrzeiliger Text stehen.}; \node[decision] (n3) {Hier sollte dann ein langer Text stehen, der noch mehr Zeilen braucht.}; \auxA{n1}{0}\auxA{n2}{2}\auxA{n3}{4} \end{tikzpicture} \begin{tikzpicture}[gridded,start chain=going right, node distance=+0pt, nodes={on chain}, stretch Diamond to height, decision/.append style={minimum height=+5cm}] \node[decision] (n1) {Mein Text}; \node[decision] (n2) {Hier sollte ein mehrzeiliger Text stehen.}; \node[decision] (n3) {Hier sollte dann ein langer Text stehen, der noch mehr Zeilen braucht.}; \auxA{n1}{0}\auxA{n2}{2}\auxA{n3}{4} \end{tikzpicture} \end{document} ## Output ![alt text][1]![alt text][2] [1]: http://texwelt.de/wissen/upfiles/de2708-0.png [2]: http://texwelt.de/wissen/upfiles/de2708-1.png
Klicke auf Einblenden/Ausblenden von Überarbeitungen 3

15 Dez '13, 14:30

Qrrbrbirlbel's gravatar image

Qrrbrbirlbel
2.9k3815

Wie auch immer die Definition für „elegant“ in diesem Fall lautet, hier ist eine alternatives `Diamond`-Shape, das auf `diamond` basiert und sich nur in der Definition des `\outernortheast`-„Anchors“ von dieser unterscheided. Ist `stretch Diamond to width` gesetzt, wird der in `/pgf/minimum width` gespeicherte Wert als fixe Rhombus-Breite interpretiert und der `aspect` dementsprechend gesetzt. Es wird dabei kein besonderer Test durchgeführt. Ist die Rhombus-Breite nur wenig größer als die Text-Breite inklusiver des doppelten `inner xsep`s, so kann es zu *sehr* hohen TikZ-Pictures oder zu Problem kommen, wenn der `aspect` eben gegen ∞ geht. Ist die `minimum width` sogar kleiner als die Breite, ist der eigentliche Rhombus einfach zu klein. Für `stretch Diamond to height` gilt Entsprechendes. ## Code \documentclass[margin=2mm,tikz]{standalone} \usetikzlibrary{shapes.geometric,chains,backgrounds} \makeatletter \newif\ifpgf@sh@Diamond@to@width \newif\ifpgf@sh@Diamond@to@height \pgfset{stretch Diamond to width/.is if=pgf@sh@Diamond@to@width} \pgfset{stretch Diamond to height/.is if=pgf@sh@Diamond@to@height} \pgfdeclareshape{Diamond}{% \savedanchor\outernortheast{% from tikzlibrary.shapes.geometric.code.tex with adaptions % % Calculate width and height of the inner rectangle % \pgf@xa=.5\wd\pgfnodeparttextbox% \pgfmathsetlength\pgf@xc{\pgfkeysvalueof{/pgf/inner xsep}}% \advance\pgf@xa by\pgf@xc% \pgf@ya=.5\ht\pgfnodeparttextbox% \advance\pgf@ya by.5\dp\pgfnodeparttextbox% \pgfmathsetlength\pgf@yc{\pgfkeysvalueof{/pgf/inner ysep}}% \advance\pgf@ya by\pgf@yc% % % Calculate width and height of diamond % \pgfmathsetlength\pgf@xb{\pgfkeysvalueof{/pgf/minimum width}}% \pgfmathsetlength\pgf@yb{\pgfkeysvalueof{/pgf/minimum height}}% \pgf@xb=.5\pgf@xb \pgf@yb=.5\pgf@yb \ifpgf@sh@Diamond@to@width \pgfmathsubtract@{\pgf@sys@tonumber\pgf@xb}{\pgf@sys@tonumber\pgf@xa}% \pgfmathdivide@{\pgfmathresult}{\pgf@sys@tonumber\pgf@ya}% \pgfsetshapeaspect{\pgfmathresult}% \else\ifpgf@sh@Diamond@to@height \pgfmathsubtract@{\pgf@sys@tonumber\pgf@yb}{\pgf@sys@tonumber\pgf@ya}% \pgfmathdivide@{\pgf@sys@tonumber\pgf@xa}{\pgfmathresult}% \pgfsetshapeaspect{\pgfmathresult}% \fi\fi \pgf@x=\pgf@xa% \advance\pgf@x by\pgfshapeaspect\pgf@ya% \pgf@y=\pgfshapeaspectinverse\pgf@xa% \advance\pgf@y by\pgf@ya% \ifpgf@sh@Diamond@to@width\else\ifpgf@sh@Diamond@to@height\else % % Check against minimum height/width % \pgf@xb=.5\pgf@xb% % \ifdim\pgf@x<\pgf@xb% % yes, too small. Enlarge... \pgf@x=\pgf@xb% \fi% \pgf@yb=.5\pgf@yb% \fi% \ifdim\pgf@y<\pgf@yb% % yes, too small. Enlarge... \pgf@y=\pgf@yb% \fi% \fi\fi % % Add outer border % \pgfmathsetlength\pgf@xa{\pgfkeysvalueof{/pgf/outer xsep}}% \advance\pgf@x by\pgf@xa% \pgfmathsetlength\pgf@ya{\pgfkeysvalueof{/pgf/outer ysep}}% \advance\pgf@y by\pgf@ya% }% \savedanchor\text{% \pgf@x=-.5\wd\pgfnodeparttextbox% \pgf@y=-.5\ht\pgfnodeparttextbox% \advance\pgf@y by.5\dp\pgfnodeparttextbox% }% \inheritanchor[from=diamond]{text}% \inheritanchor[from=diamond]{center}% \inheritanchor[from=diamond]{mid}% \inheritanchor[from=diamond]{base}% \inheritanchor[from=diamond]{north}% \inheritanchor[from=diamond]{south}% \inheritanchor[from=diamond]{west}% \inheritanchor[from=diamond]{east}% \inheritanchor[from=diamond]{north east}% \inheritanchor[from=diamond]{south east}% \inheritanchor[from=diamond]{north west}% \inheritanchor[from=diamond]{south west}% \inheritanchorborder[from=diamond]% \inheritbackgroundpath[from=diamond]} \makeatother \tikzset{decision/.style={draw,Diamond,text width=+3cm,align=center}} \newcommand*\auxA[2]{% fixed inner seps \draw[dashed] ([shift={(-.3333em,-.3333em-#2\baselineskip)}]#1.text) rectangle ([shift={(-.3333em,-.3333em-#2\baselineskip)}, rotate around=180:(#1.center)]#1.text);} \begin{document} \begin{tikzpicture}[gridded,start chain=going below, node distance=+0pt, nodes={on chain}, stretch Diamond to width, decision/.append style={minimum width=+5cm}] \node[decision] (n1) {Mein Text}; \node[decision] (n2) {Hier sollte ein mehrzeiliger Text stehen.}; \node[decision] (n3) {Hier sollte dann ein langer Text stehen, der noch mehr Zeilen braucht.}; \auxA{n1}{0}\auxA{n2}{2}\auxA{n3}{4} \end{tikzpicture} \begin{tikzpicture}[gridded,start chain=going right, node distance=+0pt, nodes={on chain}, stretch Diamond to height, decision/.append style={minimum height=+5cm}] \node[decision] (n1) {Mein Text}; \node[decision] (n2) {Hier sollte ein mehrzeiliger Text stehen.}; \node[decision] (n3) {Hier sollte dann ein langer Text stehen, der noch mehr Zeilen braucht.}; \auxA{n1}{0}\auxA{n2}{2}\auxA{n3}{4} \end{tikzpicture} \end{document} ## Output ![alt text][1]![alt text][2] [1]: http://texwelt.de/wissen/upfiles/de2708-0.png [2]: http://texwelt.de/wissen/upfiles/de2708-1.png
Klicke auf Einblenden/Ausblenden von Überarbeitungen 2

15 Dez '13, 02:44

Qrrbrbirlbel's gravatar image

Qrrbrbirlbel
2.9k3815

Klicke auf Einblenden/Ausblenden von Überarbeitungen 1

15 Dez '13, 02:23

Qrrbrbirlbel's gravatar image

Qrrbrbirlbel
2.9k3815