TikZ 'auf halbem Weg', der über die 'to'-Operation Bescheid weiß
Dies ist ungefähr das Gleiche wie / Follow-up: TikZ-Koordinate, die sich auf die letzte "aktuelle Koordinate" bezieht.
Die Antwort auf diese Frage schlägt vor, dass ich to
anstelle von verwenden soll, --
damit ich mich auf \tikztostart
die "aktuelle Koordinate" beziehen kann, die einwandfrei funktioniert, bis ich versuche, sie zu verwenden node[midway]
. Erweiterung des ursprünglichen Beispiels:
\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}
Ausgänge (der linke ist korrekt):

Es sieht für mich so aus, als midway
wüsste es nichts to
und nimmt das midway
aus dem vorherigen Pfadsegment.
Wie kann ich midway
wissen, dass der Knoten an den to
Unterpfad angehängt werden soll? Oder eine andere Antwort auf meine vorherige Frage, die diesen Fall behandelt?
Antworten
Die Antwort von Ti k Zling ist großartig und außerdem können wir einfach die Reihenfolge der \node[]{...}
: von tauschen
\draw (origin) -| (1,1) to (\tikztostart-|origin) node [midway,above] {hi};
zu
\draw (origin) -| (1,1) to node [midway,above] {hi} (\tikztostart-|origin);
Wir können sogar das herausnehmen, midway
da Ti k Z es standardmäßig auf die Mitte des Pfades zwischen den beiden Koordinaten einstellt, zwischen denen es liegt:
\draw (origin) -| (1,1) to node [above] {hi} (\tikztostart-|origin);
Ein weiterer Tipp ist die Verwendung des pos
Schlüssels, der ein Dezimalargument zwischen 0,0 und 1,0 für eine präzise Platzierung akzeptiert.

\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\coordinate (origin) at (0,0);
\draw (origin) -| (1,1) -- (1,1-|origin)
node [midway,above] {hi};
\begin{scope}[xshift=2cm]
\coordinate (origin) at (0,0);
\draw (origin) -| (2,1) to node [above] {hi} (\tikztostart-|origin);
\end{scope}
\begin{scope}[xshift=5cm]
\coordinate (origin) at (0,0);
\draw (origin) -| (2,1) to node [pos=0.25, above] {hi} (\tikztostart-|origin);
\end{scope}
\end{tikzpicture}
\end{document}
Ihre Beobachtung ist richtig. Es gibt bereits den Kommentar von M. Al Jumaily , der eine mögliche Lösung zeigt. Eine andere Lösung, die wohl bequemer ist, weil sie die Kantenbeschriftungen auch für geneigte Pfade gut platziert, ist die Verwendung des edge label
Schlüssels. Bitte beachten Sie, dass das Problem, auf das Sie stoßen, nichts damit zu tun hat, \tikztostart
sondern nur mit to
.
\documentclass[tikz,margin=1cm]{standalone}
\begin{document}
\begin{tikzpicture}
\begin{scope}[local bounding box=1]
\coordinate (origin) at (0,0);
\draw (origin) -| (1,1) -- (1,1-|origin)
node [midway,above] {hi};
\end{scope}
\begin{scope}[xshift=2.5cm,local bounding box=2]
\coordinate (origin) at (0,0);
\draw (origin) -| (1,1) coordinate (tmp) to (tmp-|origin)
node [midway,above] {hi};
\end{scope}
\begin{scope}[xshift=5cm,local bounding box=3]
\coordinate (origin) at (0,0);
\draw (origin) -| (1,1) to[edge label'={hi}] (\tikztostart-|origin);
\end{scope}
%
\path foreach \X [count=\Y] in {--,to,to w/ edge label}
{(\Y.south) node[below=1em,font=\sffamily]{\X}};
\end{tikzpicture}
\end{document}
