The red rectangle is in the correct position, but I need the blue ones to be 4 and 8mm to the right of the red on the same height (not below, as my code makes it).

What is wrong with my use of ++?


\tikzset{bar1mm/.style={shape=rectangle, fill=blue, minimum height=5mm, minimum width=1mm, anchor=west}}
\node[bar1mm, fill=red] at (10mm,10mm) {}
++(4mm,0mm) node[bar1mm] {}
++(4mm,0mm) node[bar1mm] {};


I actually need to position a lot of nodes, and the code here is just a minimum workable example, which is why I prefer ++.


The first node uses its own at mechanism such that the path pen is still at (0,0). This is because \node is (roughly) short for \path node. And every path automatically assumes to be at \pgfpointorigin at the start.

You can start your path as

\path (10mm,10mm) node[bar1mm,...

Then the pen is moved to (10mm,10mm) and the rest follows.

\begin{tikzpicture}[bar1mm/.style={shape=rectangle, fill=blue, minimum height=5mm, minimum width=1mm, anchor=west}]
\node (o) at (0,0) {O};
\path (10mm,10mm)node [bar1mm, fill=red]  {}
++(4mm,0mm) node[bar1mm] {}
++(4mm,0mm) node[bar1mm] {};

enter image description here

| improve this answer | |

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.