13

I used to make a chain diagram in tikz, like described in the manual p. 59 ff, but in contrast to the manual, my nodes are overlapping. I tried to use the "node distance" option but i doesn't seem to work. Below is the minimal working example (writeLatex.com):

\documentclass[12pt]{scrartcl}

\usepackage{tikz}

\begin{document}

\begin{figure}[tb]
    \begin{center}
    \begin{tikzpicture}[
            % copy to preamble to use it everywhere \tikzset{node/.style...}
            node/.style={
                % shape
                rectangle,
                rounded corners=1mm,
                minimum size=6mm,
                %border
                thick,
                draw,
            },
            dummy/.style={
                % shape
                rectangle,
                rounded corners=1mm,
                minimum size=6mm,
                %border
                thick,
            },
            node distance=10mm
            ]
            \node(wadl)[node]{WADL-Datei};
            \node(xsd1)[node,below left of=wadl]{XSD-Datei};
            \node(...)[dummy,below of=wadl]{\ldots};
            \node(xsd3)[node,below right of=wadl]{XSD-Datei};
            \node(test)[node,right of=wadl]{test};

            \path(wadl) edge[->] (test);
        \end{tikzpicture}   
    \end{center}
    \caption{Codegeneratorsystem}
    \label{fig:codegeneratorsystem}
\end{figure}

\end{document}

enter image description here

  • Related (and explains this behavior): Difference between "right of=" and "right=of" in PGF/TikZ – Qrrbrbirlbel Jun 18 '13 at 16:08
  • By the way, you talk of chains and use the tikz-chains tag but actually do not use the chains library (which uses the superior positioning library automatically and can simplify the creation of chain diagrams in certain aspects). Also, a node name of ... calls for trouble as TikZ uses the . to separate node name and node anchor in the implicit node coordinate syntax. You won’t be able to reference any of ...’s anchors nor use it with the positioning library as a reference node. – Qrrbrbirlbel Jun 18 '13 at 16:13
13

To have the nodes properly positionated relative to other nodes, you have to include the positioning tikz library. and change the syntax of your relative positioning from below of=node to below = of node, i.e., the equal sign comes before the of keyword.

This way:

\usetikzlibrary{positioning}

\begin{figure}[tb]
    \begin{center}
    \begin{tikzpicture}[
            % copy to preamble to use it everywhere \tikzset{node/.style...}
            node/.style={
                % shape
                rectangle,
                rounded corners=1mm,
                minimum size=6mm,
                %border
                thick,
                draw,
            },
            dummy/.style={
                % shape
                rectangle,
                rounded corners=1mm,
                minimum size=6mm,
                %border
                thick,
            },
            node distance=10mm
            ]
            \node(wadl)[node]{WADL-Datei};
            \node(xsd1)[node,below left=of wadl]{XSD-Datei};
            \node(...)[dummy,below= of wadl]{\ldots};
            \node(xsd3)[node,below right=of wadl]{XSD-Datei};
            \node(test)[node,right=of wadl]{test};

            \path(wadl) edge[->] (test);
        \end{tikzpicture}   
    \end{center}
    \caption{Codegeneratorsystem}
    \label{fig:codegeneratorsystem}
\end{figure}

Which produces this result:

Result

  • I'm always amazed how fast i get an answer here :) The tikz manual seems to be a bit misleading, because \usetikzlibrary{positioning} is mentioned only one time in chapter 16. – klingt.net Jun 18 '13 at 15:00
  • While I don’t know OP’s expectation of the diagram, one can left-align the test and the XSD-Datei node by using node distance=10mm and 10mm, this changes the behavior of the combines keys like below right. – Qrrbrbirlbel Jun 18 '13 at 16:18
5

Just add

\usetikzlibrary{positioning}

to your preamble and change your usage of positioning to:

\node(wadl)[node]{WADL-Datei};
\node(xsd1)[node,below left = of wadl]{XSD-Datei};
\node(...)[dummy,below = of wadl]{\ldots};
\node(xsd3)[node,below right = of wadl]{XSD-Datei};
\node(test)[node,right = of wadl]{test};
1

An other option

    \node(wadl)[node]{WADL-Datei};
    \node(xsd1)[node,below left=10pt and 10pt of wadl ]{XSD-Datei};
    \node(...)[dummy,below of=wadl]{\ldots};
    \node(xsd3)[node,below right=10pt and 10pt of wadl]{XSD-Datei};
    \node(test)[node,right=10pt of wadl]{test};
    \path(wadl) edge[->] (test);

enter image description here

  • I dont think that this is a real option, because (semi-)manual positioning of nodes is towards the intentions to use tikz/pgf for graphics creation. – klingt.net Jul 4 '13 at 12:11

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.