
Ich möchte zwei Bilder zeichnen, das zweite Bild sollte unter dem ersten sein. Das habe ich derzeit:
Wie kann das zweite Bild die gleiche X-Koordinate wie das erste Bild erhalten?
Code:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\begin{document}
\tikzset{
pics/vhsplit/.style n args = {3}{
code = {
\node (A) at (0,0) {#1};
\node[anchor=south west] (B) at (A.east) {#2};
\node[anchor=north west] (C) at (A.east) {#3};
\node[inner sep=0pt, outer sep=0pt, draw, rounded corners, fit=(A)(B)(C)] (-box) {};
\draw (B.north west) -- (C.south west)
(B.south west) -- (C.north east);
}
}
}
\begin{tikzpicture}
\pic (a) {vhsplit={a}{2.0}{6.0}};
\pic[below=10mm of a-box.south] (b) {vhsplit={b}{-3.0}{-4.0}};
\end{tikzpicture}
\end{document}
Antwort1
Die Bilder sind nicht so intelligent wie die Knoten. Es ist immer der Ursprung des Bildes, der an der angegebenen Stelle platziert wird.
Wenn das alles ist, was Sie brauchen, ist es möglicherweise einfacher, einen normalen Knoten mit einem innerhalb des Knotens zu verwenden tabular
. Hier sind drei Ansätze:
- Normaler Text und eine Tabelle mit zwei Zeilen und einer Spalte
→vhsplit
- Eine Tabelle mit zwei Zeilen und zwei Spalten, in die ein →
#1
eingefügt wird .\multirow
vhsplit'
- A
rectangle split
Formaus dershapes.multipart
Bibliothek, wieder mit tabellarischer Darstellung wie unter 1.
→vhsplit''
Da die Zeilen der Tabelle die Knotengrenzen berühren müssen, setze ich das inner sep
s (Standard .3333em) auf Null und füge dieses Leerzeichen an den entsprechenden Stellen erneut ein.
Die vertikale Platzierung des linken Teils ist etwas variabel. Wählen Sie diejenige aus, die am besten zu Ihrem Anwendungsfall passt (die Lösungen sind in dieser Reihenfolge rot/grün/blau eingefärbt und mit übereinander gelegt opacity=.3333
):
Code
\documentclass[tikz,border=2mm]{standalone}
\usepackage{hhline}
\usepackage{multirow}
\usetikzlibrary{positioning}
\tikzset{
vhsplit/.style n args={3}{% text and a tabular
shape=rectangle, draw, rounded corners, inner sep=+0pt,
node contents={%
\setlength{\tabcolsep}{.3333em}%
\hspxsep#1\hspxsep
\begin{tabular}{|l@{\hspxsep}}
\vstysep$#2$\\\hhline{|-}
\vstysep$#3$%
\end{tabular}}},
vhsplit'/.style n args={3}{
shape=rectangle, draw, rounded corners, inner sep=+0pt,
node contents={% multirow in a tabular
\setlength{\tabcolsep}{.3333em}%
\begin{tabular}{l|l@{\hspxsep}}
\multirow{2}{*}{#1} &
\vstysep$#2$\\\hhline{~|-}
& \vstysep$#3$%
\end{tabular}}}}
\usetikzlibrary{shapes.multipart}
\tikzset{
vhsplit''/.style n args={3}{
shape=rectangle split, rectangle split horizontal, rectangle split parts=2,
draw, rounded corners, inner sep=+0pt,
node contents={% two nodeparts and a tabular
\hspxsep#1\hspxsep\null
\nodepart{two}\setlength{\tabcolsep}{.3333em}%
\begin{tabular}{l}
\vstysep$#2$\\\hline
\vstysep$#3$
\end{tabular}}}}
\newcommand*\hspxsep{\hspace{.3333em}}
\newcommand*\vstysep{\rule{0pt}{1.0333em}}
\begin{document}
\begin{tikzpicture}
\node (a) [vhsplit={a}{ 2.0} {6.0}];
\node[below=of a] (b) [vhsplit={b}{-3.0}{-4.0}];
\tikzset{xshift=2cm}
\node (a) (a) [vhsplit'={a} {2.0} {6.0}];
\node[below=of a] (b) [vhsplit'={b}{-3.0}{-4.0}];
\tikzset{xshift=2cm}
\node (a) [vhsplit''={a} {2.0} {6.0}];
\node[below=of a] (b) [vhsplit''={b}{-3.0}{-4.0}];
\end{tikzpicture}
\end{document}
Ausgabe
Antwort2
Versuche dies:
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning}
\usetikzlibrary{fit}
\begin{document}
\tikzset{
pics/vhsplit/.style n args = {3}{
code = {
\node (A) at (0,0) {#1};
\node[anchor=south west] (B) at (A.east) {#2};
\node[anchor=north west] (C) at (A.east) {#3};
\node[inner sep=0pt, outer sep=0pt, draw, rounded corners, fit=(A)(B)(C)] (-box) {};
\draw (B.north west) -- (C.south west)
(B.south west) -- (C.north east);
}
}
}
\begin{tikzpicture}{scale=3} % <-- changed
\pic (a) {vhsplit={a}{2.0}{6.0}};
\pic[xshift=0cm,yshift=-1cm] (b) {vhsplit={b}{-3.0}{-4.0}};
\end{tikzpicture}
\end{document}
AUSGABE: