von Stefan Kottwitz » Mi 15. Jun 2022, 18:54
Hallo Yoschi,
willkommen im Forum!
Ich finde es super, dass Du gleich ein komplettes Codebeispiel postest. Das probiere ich doch gern aus und hier ist mein Vorschlag.
Zeichne doch einfach die Linie zusammen mit den Nodes, denn die werden erst nach dem gezeichneten Pfad drauf platziert und damit ist die Linie überdeckt:
\draw (0,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
minimum height=1.5cm, align=center] (1){Block 1}
-- (4,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
minimum height=1.5cm, align=center] (2) at (4,0) {Block 2};
Testbares Komplettbeispiel, einfach auf "LaTeX-Ausgabe" klicken:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\definecolor{grey}{RGB}{200,200,200}
\makeatletter
\pgfkeys{/pgf/.cd,
parallelepiped offset x/.initial=2mm,
parallelepiped offset y/.initial=2mm
}
\pgfdeclareshape{parallelepiped}
{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{north west}
\inheritanchor[from=rectangle]{north east}
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{mid}
\inheritanchor[from=rectangle]{mid west}
\inheritanchor[from=rectangle]{mid east}
\inheritanchor[from=rectangle]{base}
\inheritanchor[from=rectangle]{base west}
\inheritanchor[from=rectangle]{base east}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{south west}
\inheritanchor[from=rectangle]{south east}
\backgroundpath{
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/parallelepiped offset x}}
\pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/parallelepiped offset y}}
\def\ppd@offset{\pgfpoint{\pgfutil@tempdima}{\pgfutil@tempdimb}}
\pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
\pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
\pgfpathclose
\pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@ya}}{\ppd@offset}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xa}{\pgf@yb}}{\ppd@offset}}
\pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
\pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
minimum height=1.5cm, align=center] (1){Block 1}
-- (4,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
minimum height=1.5cm, align=center] (2) at (4,0) {Block 2};
\end{tikzpicture}
\end{document}
Stefan
Hallo Yoschi,
willkommen im Forum!
Ich finde es super, dass Du gleich ein komplettes Codebeispiel postest. Das probiere ich doch gern aus und hier ist mein Vorschlag.
Zeichne doch einfach die Linie zusammen mit den Nodes, denn die werden erst nach dem gezeichneten Pfad drauf platziert und damit ist die Linie überdeckt:
[code]\draw (0,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
minimum height=1.5cm, align=center] (1){Block 1}
-- (4,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
minimum height=1.5cm, align=center] (2) at (4,0) {Block 2};[/code]
[attachment=0]quader.png[/attachment]
Testbares Komplettbeispiel, einfach auf "LaTeX-Ausgabe" klicken:
[code]\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usepackage{xcolor}
\definecolor{grey}{RGB}{200,200,200}
\makeatletter
\pgfkeys{/pgf/.cd,
parallelepiped offset x/.initial=2mm,
parallelepiped offset y/.initial=2mm
}
\pgfdeclareshape{parallelepiped}
{
\inheritsavedanchors[from=rectangle] % this is nearly a rectangle
\inheritanchorborder[from=rectangle]
\inheritanchor[from=rectangle]{north}
\inheritanchor[from=rectangle]{north west}
\inheritanchor[from=rectangle]{north east}
\inheritanchor[from=rectangle]{center}
\inheritanchor[from=rectangle]{west}
\inheritanchor[from=rectangle]{east}
\inheritanchor[from=rectangle]{mid}
\inheritanchor[from=rectangle]{mid west}
\inheritanchor[from=rectangle]{mid east}
\inheritanchor[from=rectangle]{base}
\inheritanchor[from=rectangle]{base west}
\inheritanchor[from=rectangle]{base east}
\inheritanchor[from=rectangle]{south}
\inheritanchor[from=rectangle]{south west}
\inheritanchor[from=rectangle]{south east}
\backgroundpath{
% store lower right in xa/ya and upper right in xb/yb
\southwest \pgf@xa=\pgf@x \pgf@ya=\pgf@y
\northeast \pgf@xb=\pgf@x \pgf@yb=\pgf@y
\pgfmathsetlength\pgfutil@tempdima{\pgfkeysvalueof{/pgf/parallelepiped offset x}}
\pgfmathsetlength\pgfutil@tempdimb{\pgfkeysvalueof{/pgf/parallelepiped offset y}}
\def\ppd@offset{\pgfpoint{\pgfutil@tempdima}{\pgfutil@tempdimb}}
\pgfpathmoveto{\pgfqpoint{\pgf@xa}{\pgf@ya}}
\pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
\pgfpathlineto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
\pgfpathclose
\pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@ya}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@ya}}{\ppd@offset}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xa}{\pgf@yb}}{\ppd@offset}}
\pgfpathlineto{\pgfqpoint{\pgf@xa}{\pgf@yb}}
\pgfpathmoveto{\pgfqpoint{\pgf@xb}{\pgf@yb}}
\pgfpathlineto{\pgfpointadd{\pgfpoint{\pgf@xb}{\pgf@yb}}{\ppd@offset}}
}
}
\makeatother
\begin{document}
\begin{tikzpicture}
\draw (0,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
minimum height=1.5cm, align=center] (1){Block 1}
-- (4,0) node[parallelepiped,draw=black,fill=grey, minimum width=2.5cm,
minimum height=1.5cm, align=center] (2) at (4,0) {Block 2};
\end{tikzpicture}
\end{document}[/code]
Stefan