21

I’m trying to add offsets to two coordinates with tikz like this:

\draw[line width=4] (coorda) ++(0.3pt,0) -- (coordb) ++(-0.3pt,0);

The first ++ instruction works just fine, but the second one has no effect. The problem is that the thick horizontal line does not flush with the vertical line (showing coordb in this image):

Offset needed

I had a look at the documentation but I couldn’t figure it out. I will provide a MWE if the solution is not trivial. Maybe there is a better way to join these lines, that does not rely on manually adding offsets?

Lenar Hoyt
  • 1,629
  • A different question, but the solution is the same: http://tex.stackexchange.com/a/207738/21344 – Paul Gessler Oct 27 '14 at 23:25
  • Bottom line, the second ++ does have an effect, but since you're not drawing anything (no --, to[...], -|, etc.) between the last two coordinates, it never shows in the output. – Paul Gessler Oct 27 '14 at 23:27
  • @PaulGessler: Thanks. Adding another -- solved it! I guess, this question can be closed as duplicate. – Lenar Hoyt Oct 27 '14 at 23:31
  • This question is more general, so I think it's OK to leave it open. Whatever you feel is best. :-) Plus now @percusse has provided yet another method in his fine answer. – Paul Gessler Oct 27 '14 at 23:36

1 Answers1

36

++ instructions are pen instructions (in PostScript lingo). What it does is to lift the pen and move that much added to the current point. Single + is another instruction but in the end the pen is brought back to the current point.

So effectively what you are doing is

\draw[line width=4] % Set pen properties
(coorda) % move to coorda labeled point. This is the current point now.
++(0.3pt,0) % move the pen 0.3pt to the right relative to coorda
-- %put the pen down
(coordb) % draw the line. This is the current point now.
 ++(-0.3pt,0) % lift the pen and move 0.3pt to the left relative to coordb, 
              % if there was a -- here it would still draw it
; % we are done

Instead you can shift the points individually, for example

\draw[line width=4] ([xshift=0.3pt]coorda) -- ([xshift=-0.3pt]coordb);
percusse
  • 157,807