8

I want to generate a simple organigram with reasonable-looking distances in x and y direction. How can I get equidistant distances between the nodes?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}
\begin{tikzpicture}
[topline/.style={rectangle,rounded corners,fill=red,xshift=3cm, yshift=2.5cm, minimum width=15mm,minimum height=10mm},
botline/.style={rectangle,rounded corners,fill=orange,xshift=3cm, yshift=2cm, minimum width=15mm,minimum height=10mm},
]
\node at (0,0) [topline] {A};
\node at (1,0) [topline] {B};
\node at (2,0) [topline] {C};
\node at (0,-1) [botline] {D};
\node at (0,-2) [botline] {E};
\end{tikzpicture}

\end{document}

tikz node positioning

6

You're using different minimum width and minimum height. Set them both to the same value and you should get the distances correct.

If you add the line

\tikzset{x=15mm,y=15mm}

before beginning the picture, you'll get a nicer result. Also make sure that your xshift and yshift are the same and you'll get something like

enter image description here

Finally, since a lot of your styles are duplicated, I separate out the duplication.

Here is the code for the last image

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}
[
    x=15mm,y=15mm,
    mybox/.style={rectangle,rounded corners,xshift=1cm,yshift=1cm,minimum width=15mm, minimum height=15mm},
    topline/.style={mybox,fill=red},
    botline/.style={mybox,fill=orange},
]
\node at (0,0) [topline] {A};
\node at (1,0) [topline] {B};
\node at (2,0) [topline] {C};
\node at (0,-1) [botline] {D};
\node at (0,-2) [botline] {E};
\end{tikzpicture}

\end{document}
1
  • x=15mm,y=15mm should be included in option of tikzpicture environment. Jan 28 '13 at 22:37

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.