2

Is it possible to specify the distance between the nodes using the relative positioning (such as below of) so this doesn't happen:

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usepackage{flowchart}
\usetikzlibrary{positioning}
\begin{document}
    \pagestyle{empty}


\tikzstyle{decision_lb} = [diamond, draw, fill = blue!20, 
text badly centered, node distance=3cm, text width = ]
% Operation
\tikzstyle{c_op} = [rectangle, draw, fill = blue!20, 
 text centered, minimum height=4em,  text width=,minimum size=2em]

\begin{tikzpicture}[node distance = 1.5cm, auto]
\node[decision_lb](dec1){veeeery looooooooooooooooonnnnnnnnnnnnnnnnnggggggggggggggg text};
%yes branch
\node[c_op, below of = dec1] (op4) {$formulas$};

\end{tikzpicture}


\end{document}

enter image description here

This is, of course, a overexaggerated example but I have the same problem in a more complicated figure.

I need some command similar to below of but it has to include the outside measures of the previous shape. I'm using no yshift but it is trial and error to find the right value to make it look good. Until now I also wasn't able to find a similar question.

Edit: I want to place op4 in the same distance as in the second example regardless of what is written in dec1.

Second example:

\documentclass{article}
\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{shapes.multipart}
\usepackage{flowchart}
\usetikzlibrary{positioning}
\begin{document}
    \pagestyle{empty}

    \tikzstyle{decision_lb} = [diamond, draw, fill = blue!20, 
    text badly centered, node distance=3cm, text width = ]
    % Operation
    \tikzstyle{c_op} = [rectangle, draw, fill = blue!20, 
     text centered, minimum height=4em,  text width=,minimum size=2em]

    \begin{tikzpicture}[node distance = 1.5cm, auto]
    \node[c_op](dec1){veeeery looooooooooooooooonnnnnnnnnnnnnnnnnggggggggggggggg text};
    %yes branch
    \node[c_op, below of = dec1] (op4) {$formulas$};
    \end{tikzpicture}

\end{document}

enter image description here

Edit2: I want the same vertical distance between my shapes. My problem is that below of = dec1 just specifies the distances between the node origins. If the text in the shape diamond gets very long the diamond gets also vertically very big, but the distance to the next shape below is not changed (cause the node origins stay the same). So I need a command that specifies the distances to the outside of the other shape.

3

i guess that you like to obtain something like this:

enter image description here

if this is not the case than please clarify your question.

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, positioning, shapes}

\begin{document}

\begin{tikzpicture}[auto,
node distance = 11mm and 22mm, 
decision_lb/.style = {diamond, draw, fill = blue!20,
                      text width=4.5em, align=flush center},
       c_op/.style = {rectangle, draw, fill = blue!20,
                      text width=5em, align=center, minimum height=4em} 
                    ]
\node (dec1) [decision_lb]          {very long text};
%yes branch
\node (op4)  [c_op, below=of dec1]  {$formulas$};

\end{tikzpicture}

\end{document}

in above mwe i do the following:

  • replace depreciated \tikzstyle with options of tikzpicture. you also can move those options to \tikzset{...}
  • clean up styles definitions from repeating text width ...
  • reduce inner sep to default value
  • use syntax defined by positioning package: below=of ... and not below of= ...

addendum (1): tell me, if now i understand you correct: you like to have the next node width the same width as previous one, i.e.: the rectangle below diamond should be the same of width as diamond?

if my guessing is (this time) correct than one of possible solution is:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, positioning, shapes}

\begin{document}

\begin{tikzpicture}[auto,
node distance = 11mm and 22mm,
decision_lb/.style = {diamond, draw, fill = blue!20,
                      align=flush center},
       c_op/.style = {rectangle, draw, fill = blue!20,
                      text width=#1 - 2*\pgfkeysvalueof{/pgf/inner xsep},
                      align=center, minimum size=4em},
                    ]
\node (dec1) [decision_lb]  {very long text};
%yes branch
\path   let \p1 = ($(dec1.west)-(dec1.east)$),
            \n1 = {veclen(\y1,\x1)} in
        node (op4) [c_op=\n1, below=of dec1]  {$formulas$};

\end{tikzpicture}

\end{document}

which gives:

enter image description here

addendum (2): as follows from last edit of question, you problem is use of wrong syntax for node distance. for correct one see last item in above list. let repeat me:

wrong: below of = dec1

correct: below = of dec1

for demonstrate this let me extend the first answer to more nodes:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, positioning, shapes}

\begin{document}

\begin{tikzpicture}[auto,
node distance = 4mm and 8mm,
decision_lb/.style = {diamond, draw, fill = blue!20,
                      text width=4.5em, align=flush center},
       c_op/.style = {rectangle, draw, fill = blue!20,
                      minimum width=5em,
                      align=center, minimum height=4em},
                    ]
\node (dec1) [decision_lb]  {very long text};
%yes branch
\node (op4) [c_op, below=of dec1]  {$formulas$}; % <-- observe syntax for distance between nodes
\node (op5) [c_op, below=of op4]   {$formulas$}; % <-- observe syntax for distance between nodes
\end{tikzpicture}

\end{document}

enter image description here

as you can see, distances between nodes are equal.

  • Thank you. It's not exactly what i wanted but i guess it wasn't clear enough. But it still could help me. I have one question. How can i achieve that the 'below= of' makes the same distances as the 'below of='? – Michael Obermeist Sep 19 '17 at 17:15
  • @MichaelObermeist, please explain what is not what you like to have. the best way is edit your question and (hand drawing) add sketch, what you like to have. – Zarko Sep 19 '17 at 17:18
  • i edited the question. Please let me know if it's still not clear. – Michael Obermeist Sep 19 '17 at 18:08
  • sorry, still have problems. see addendum to my answer, if my "crystal ball" works better :-) – Zarko Sep 19 '17 at 18:25
  • Thank you. no problem =) i wrote another edit ;) – Michael Obermeist Sep 19 '17 at 18:55
1

You could also use a matrix and let tikz work for you:

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, positioning, shapes, matrix}

\begin{document}

    \begin{tikzpicture}[
        decision_lb/.style = {diamond, draw, fill = blue!20,
            text width=4.5em, align=flush center},
        c_op/.style = {rectangle, draw, fill = blue!20,
            minimum width=5em,
            align=center, minimum height=4em},
        ]
        \matrix[matrix of nodes, 
            row sep=1.5cm, column sep=1.5cm]{
            |[decision_lb, name=dec1]| {very long text}
            & |[c_op, name= dec2]| {veeeery
            looooooooooooooooonnnnnnnnnnnnnnnnnggggggggggggggg text}\\  
            |[c_op, name= op4]| {$formulas$}
            & |[c_op, name= op5]| {$formulas$} \\
        };
    \end{tikzpicture}
\end{document}

enter image description here

  • Thank you this looks interesting. I didn't try \matrix until now. Can i set coordinates for path's also instead of nodes? – Michael Obermeist Sep 20 '17 at 14:15
  • @MichaelObermeist It's more or less like a tabular, I think it is very useful for node positioning :) – CarLaTeX Sep 20 '17 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.