4

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 ++?

\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{frame}[fragile]
\frametitle{Tikztezt}
\begin{figure}\flushleft

\begin{tikzpicture}
\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] {};
\end{tikzpicture}

\end{figure}
\end{frame}
\end{document}

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

7

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] {};
\end{tikzpicture}

enter image description here

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.