
Gibt es eine Syntax, die es erlaubt, eine Linie als Knoten in Tikz zu verwenden? Im folgenden Beispiel:
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%dummy nodes
\node (A) at (0,0) {};
\node (B) at (5,0) {};
\node (C) at (2,-5) {};
\draw (A)--(B);
\draw (C)--(2,0);
\end{tikzpicture}
\end{document}
Ich möchte etwas wie \draw (C)--[(A)--(B)]
anstelle von schreiben \draw (C)--(2,0)
. In diesem Beispiel kenne ich natürlich die Koordinaten der Knoten explizit, in meinem tatsächlichen Diagramm jedoch nicht, und jedes Mal, wenn ich etwas hinzufüge, das die Größe ändert, muss ich die Koordinate des expliziten Knotens durch Ausprobieren anpassen.
Danke
Antwort1
local bounding box=<node name>
Sie brauchen hier eine Option .
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
%dummy nodes
\node (A) at (0,0) {};
\node (B) at (5,0) {};
\node (C) at (2,-5) {};
% this creates a rectangle node named AB
\draw[local bounding box=AB] (A)--(B);
\draw (C) |- (AB);
\end{tikzpicture}
\end{document}
Aktualisieren:Und eine Version mit Projektionsmodifikator:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
%dummy nodes
\node (A) at (0,0) {};
\node (B) at (5,0) {};
\node (C) at (2,-5) {};
\draw (A)--(B);
% draw a line from node C to the projection of C on line A to B
% see pgfmanual, sec. 13.5.5 _The Syntax of Projection Modifiers_
\draw (C) |- ($(A)!(C)!(B)$);
\end{tikzpicture}
\end{document}