This is sort of the same as/follow up to this: TikZ coordinate that refers to the last "current coordinate"
The answer to that question suggests me to use to
instead of --
so that I can use \tikztostart
to refer to the "current coordinate", which works fine until I try to use node[midway]
. Expanding on the original example:
\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0);
\draw (origin) -| (1,1) -- (1,1-|origin) % this uses --
node [midway,above] {hi};
\begin{scope}[xshift=2cm]
\coordinate (origin) at (0,0);
\draw (origin) -| (1,1) to (\tikztostart-|origin) % this uses to
node [midway,above] {hi};
\end{scope}
\end{tikzpicture}
\end{document}
outputs (the left one is correct):
It looks to me that midway
doesn't know about to
and takes the midway
from the previous path segment.
How can I make midway
know that it's supposed to attach the node to the to
subpath? Or another answer to my previous question that copes with this case?
\draw (origin) -| (1,1) to node [midway,above] {hi} (\tikztostart-|origin);
sufficient? – M. Al Jumaily Nov 29 '20 at 3:39node [midway]
; cool, let me take the last subpath I made and put a node in the middle". Putting it before the final coordinate makes little sense to me, as the end of the path is not known, if you are doing things as you read them (which is more or less what TikZ does). What it looks like is that a subpath made withto
is sort of "forgotten" after the segment is drawn, and the "last subpath" from my reasoning above is taken as the last one with--
. – LaTeXer Nov 29 '20 at 5:33