Ich versuche, ein Diagramm zu erstellen, indem ich die Knoten mithilfe der relativen Platzierung manuell platziere. Ich habe jedoch einige Probleme mit der Art und Weise, wie die Knoten platziert werden. Ich habe versucht, es in ein MWE einzubinden:
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
test node/.style={rectangle, draw, text height=1.5ex, text depth=0.25ex}
]
\small
\node (a) [test node] {First node};
\node (b) [test node, above right=of a] {Upper branch 1};
\node (c) [test node, below right=of a] {Lower branch 1};
\begin{scope}[red]
\foreach \pos/\n in {above right/x, right/y, below right/z}
{
\node (\n) [circle, draw, \pos=of a] {};
\foreach \a in {north, center, south}
{
\draw[shift=(\n.\a)] plot [mark=x] coordinates{(0,0)};
}
}
\foreach \n in {x, y, z}
\draw (0,2 -| \n.center) -- ++(0,-4);
\node [circle, draw, below=of a] at (3,0) {};
\end{scope}
\end{tikzpicture}
\end{document}
Wie Sie sehen, stimmt die Platzierung der Kreise und der Textknoten relativ zum ersten Knoten nicht überein. Zweitens sind die drei Kreise nicht horizontal ausgerichtet. Und als dritter „Bonus“ stimmt der letzte Kreis, der mit einer Kombination aus dem below
Schlüssel und einer expliziten Position in x-Richtung platziert wurde, auf eine dritte Weise nicht überein.
Was ist die richtige Art, solche Knoten (mit unterschiedlichen Formen und unterschiedlichen Platzierungsmöglichkeiten) zu platzieren, ohne manuell Koordinaten hinzuzufügen? Ich muss verschiedene Formen kombinieren und einige X-Koordinaten explizit festlegen, um die Knoten richtig in den verschiedenen Zweigen zu verteilen ...
Bearbeiten: Zur Klarstellung: Ich möchte die Kreise und Rechtecke vertikal ausrichten und ihre Westanker horizontal ausrichten.
Antwort1
\node (b) [test node, above right=of a] {Upper branch 1};
setzt den anchor
Knoten b
auf south west
undnichtzu west
. Dann b.south west
wird 1 cm rechts und 1 cm oberhalb von positioniert a.north east
. Und wenn der Knoten ein Kreis ist, besteht x
zwischen Anker south west
und ein Unterschied in der -Richtung west
.
Wenn der Anker von b
sein soll, müssen Sie west
stattdessen verwendensouth west
anchor=west
nachdie Option above right=of a
.
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
test node/.style={rectangle, draw, text height=1.5ex, text depth=0.25ex},
node distance=1cm and 1cm
]
\small
\node (a) [test node] {First node};
\node (b) [test node, above right=of a,anchor=west] {Upper branch 1};
\node (c) [test node, below right=of a,anchor=west] {Lower branch 1};
\begin{scope}[red]
\foreach \pos/\n in {above right/x, right/y, below right/z}
{
\node (\n) [circle, draw, \pos=of a,anchor=west] {};
\foreach \a in {north, center, south}
{
\draw[shift=(\n.\a)] plot [mark=x] coordinates{(0,0)};
}
}
\foreach \n in {x, y, z}
\draw (0,2 -| \n.center) -- ++(0,-4);
\node [circle, draw, below=of a] at (3,0) {};
\end{scope}
\draw[green](a.east)--+(1,0);
\draw[blue](a.north east)--++(1,0)--+(0,1);
\draw[orange](a.south east)--++(1,0)--+(0,-1);
\end{tikzpicture}
\end{document}
west
Und vielleicht möchten Sie die Anker relativ zum east
Anker von positionieren a
:
\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[
test node/.style={rectangle, draw, text height=1.5ex, text depth=0.25ex},
node distance=1cm and 1cm
]
\small
\node (a) [test node] {First node};
\node (b) [test node, above right=of a.east,anchor=west] {Upper branch 1};
\node (c) [test node, below right=of a.east,anchor=west] {Lower branch 1};
\begin{scope}[red]
\foreach \pos/\n in {above right/x, right/y, below right/z}
{
\node (\n) [circle, draw, \pos=of a.east,anchor=west] {};
\foreach \a in {north, center, south}
{
\draw[shift=(\n.\a)] plot [mark=x] coordinates{(0,0)};
}
}
\foreach \n in {x, y, z}
\draw (0,2 -| \n.center) -- ++(0,-4);
\node [circle, draw, below=of a] at (3,0) {};
\end{scope}
\draw[green](a.east)--+(1,0);
\draw[blue](a.east)++(1,0)--+(0,1);
\draw[orange](a.east)++(1,0)--+(0,-1);
\draw[purple](a.center)--++(0,-1)--+(3,0);
\end{tikzpicture}
\end{document}