3

I think I have seen some command like this before. Using + and ++ we can define coordinates relative to previous points on the path. I'm wondering whether -- also has alternative versions that allow me to draw a line starting from a previous point rather than the current one. For example, consider this MWE:

\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (0.5,0) -- +(0,1) --++ (0.5,0);
\end{tikzpicture}
\end{document}

which yields

enter image description here

What is the simplest way in which I could modify the MWE to get

enter image description here

instead?

Ideally, I would like to do it with a single \draw command and without doing stuff such as \draw (0,0) -- (0.5,0) -- +(0.5,0) (0.5,0) -- (0.5,1);, where the problem is solved by repeating one of the points. I would like to write each of the four points only once.

The reason is I'm working on an illustration which uses some random points, and I might not be able to get their coordinates again without considerably changing the implementation. Hence, in my goal each of the four points is sorted at random, and I will not be able to write them twice.

3
  • just use coordinate command?
    – user202729
    Mar 25 at 6:42
  • No, you need to repeat this coordinate (some how).
    – Zarko
    Mar 25 at 10:17
  • (0,0) -- (1,0) (0.5,0) -- ++(0,1) does all four points once each ;=) Mar 25 at 10:54

2 Answers 2

4

As mentioned in the comment, coordinate may be used:

%! TEX program = pdflatex
\documentclass[tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (0.5,0) coordinate (tmp) -- +(0,1) (tmp) --++ (0.5,0);
\end{tikzpicture}
\end{document}
6

The problem is that + does not update the current point, but it updates the starting point of the path.

A possible solution, in the case of your MWE, could be:

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (0.5,0) -- +(0,1) |-++ (0.5,0);
\end{tikzpicture}
\end{document}

or

\documentclass[tikz, border=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- +(1,0) (0.5,0) -- +(0,1);
\end{tikzpicture}
\end{document}

enter image description here

2
  • Given the coordinate is "random" I think it would be rather unlikely for |- to work as expected...
    – user202729
    Mar 25 at 16:01
  • @user202729 Using only 4 points there is no other solution, unless using coordinate as you suggested.
    – CarLaTeX
    Mar 25 at 18:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .