1

Suppose that I want to create 3 tikz nodes named a, b and c.

The nodes should be positioned in the following relational manner:

First of all, a's east anchor should be connected to b's west anchor. Furthermore, b's east anchor should be connected to c's west anchor.

What is the correct way to do this?

I tried the following code (which doesn't work). I'm not sure what is wrong with my logic here.

\begin{tikzpicture}
\node[rectangle , draw](a){A};
\node[rectangle, draw , right of = a , anchor = west](b){B};
\node[rectangle , draw , left of = a , anchor = east](c){C};    
\end{tikzpicture}
Sigur
  • 37,330

1 Answers1

1

Here are two ways. Both produce the same output.

enter image description here

Using chains:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{chains}

\begin{document}

\begin{tikzpicture}[start chain, node distance=5mm] \nodeon chain, draw{A}; \nodeon chain=going right, draw{B}; \nodeon chain=going right, draw{C}; \end{tikzpicture}

\end{document}

Using positioning:

\documentclass{article}

\usepackage{tikz} \usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}[node distance=5mm] \nodedraw{A}; \noderight=of a, draw{B}; \noderight=of b, draw{C}; \end{tikzpicture}

\end{document}

If you want to connect the nodes, you can add \draw(a)--(b)--(c); before the end of the tikzpicture. With chains, there is also the join option: \node[on chain=going right, draw, join]

enter image description here

Sandy G
  • 42,558