8

This is something very basic that I've often been slightly annoyed with when using Tikz, mostly since I think I've seen that it is possible somewhere before and I'm annoyed with myself for not remembering. However, after trying several keyword combinations, Google has not obliged me. It is of course perfectly possible that I still just haven't found the right keywords to try (English is not my native language) or that it is so basic everyone knows. The latter seems somewhat unlikely though, considering the stupendous amount of basic questions being asked all over the internet about anything whatsoever.

Anyway, here's an MWE for what I'm trying to do:

\documentclass[border=1cm]{standalone}
\usepackage{pgfplots,tikz}
\begin{document}
\begin{tikzpicture}
\draw[rounded corners=1cm] (-2,5) -- (-2,0) -- (-0.4,0);
\draw[rounded corners=1cm] (0.4,0) -- (2,0) -- (2,5);
\end{tikzpicture}
\end{document}

Output:

enter image description here

So my question is whether it is possible to do this with a single \draw command, i.e. is there an alternative to -- that will just "move my pencil" to the next coordinate given without drawing the line? Or in yet other words: can I straightforwardly suspend the draw command for a given portion of a path?

You've probably noticed my MWE isn't completely minimal since the rounded corners and even the vertical lines are actually superfluous to my question, but otherwise the question seems even more trivial than it already does. It's not that much extra work to do it the way I have (in this case) but I'm a sucker for efficiency and logical clarity. Besides, larger pictures might require (a lot) more extra work.

  • 1
    Yes you can. Did you try appending (0,0) -- (1,1) (-1,2) -- (3,5)? Is that what you mean? – percusse Jul 23 '15 at 16:36
  • @percusse Yes, that's exactly it. And it's such an embarrassingly obvious thing to try that I'm inclined to delete this question... But others might be equally dim-witted, so perhaps I should leave it be. – Wouter Jul 23 '15 at 16:39
  • Like this :\draw[rounded corners=1cm] (-2,5) -- (-2,0) -- (-0.4,0) (0.4,0) -- (2,0) -- (2,5);? – Herr K. Jul 23 '15 at 16:40
  • 2
    I think that, unless someone finds a duplicate, you should leave the question. As obvious as it might seem to you now, it could indeed be useful for other users. @percusse Would you like to provide an answer? – Gonzalo Medina Jul 23 '15 at 17:42
  • As you want to save key-strokes: \documentclass[border=1cm,tikz]{standalone}\begin{document}\tikz\draw[rounded corners=1cm] (-2,5) |- (-0.4,0) (0.4,0) -| (2,5);\end{document} – LaRiFaRi Jul 23 '15 at 19:10
5

In the basic level of PDF specs, the pen can be lifted from a point and moved to another point to continue a path with the same specifications for the initial path. These are modeled in basic layer of TikZ as \pgfpath<line,arc and so on>to and for the pen motion without ink \pgfpathmoveto

The last one in the TikZ frontend notation is basically putting nothing in between to consecutive coordinate expressions.

Hence

(0,0) -- (1,1) (-1,2) -- (3,5)

draws to (1,1) and then lifts and moves the pen to (-1,2) and continues.

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.