我正在尝试创建层次金字塔,但总是出现错误
“未发现名为 Intersection-1 的形状。”
\documentclass[tikz]{standalone}
\usetikzlibrary{shapes, arrows.meta, positioning, calc, decorations.pathreplacing, intersections}
\tikzset{every picture/.style={/utils/exec={\sffamily\small}}}
\tikzstyle{textbox} = [rectangle, minimum width = 3.5cm, minimum height = 1cm, rounded corners = 1pt, line width = 1pt, draw = black, align = center]
\tikzstyle{curlyBrace} = [decorate, decoration = {brace, amplitude = 15pt, raise = 2pt}, line width = 1pt, line cap = round]
\tikzstyle{arrow} = [solid, line width = 5pt, -{Triangle[width = 10pt, length = 10pt]}]
\tikzstyle{singleArrow} = [single arrow, minimum width = 1cm, minimum height = 4cm, draw = black, line width = 1pt]
\begin{document}
\begin{tikzpicture}[node distance = 1cm and 1cm, outer sep = 0]
\node [textbox] (hut) {hut};
\node [textbox, right = of hut] (fuss) {fuss};
\node [textbox, right = of fuss] (maus) {maus};
\node [textbox, below = 2cm of hut.west, anchor = west, minimum width = 8cm] (tao) {tao};
\node [textbox, below = 2cm of tao.west, anchor = west, minimum width = 12.5cm] (toll) {toll};
\node [textbox, below = 2cm of toll.west, anchor = west] (wer) {wer)};
\node [textbox, below = 2cm of wer.west, anchor = west] (mode) {mode};
\draw [curlyBrace] (wer.north east) -- (mode.south east);
\coordinate (A) at (6,0) {};
\coordinate (B) at (14,0) {};
\coordinate (C) at (10,4) {};
\draw[name path = AC, line width = 1pt] (A) -- (C);
\draw[name path = BC, line width = 1pt] (B) -- (C);
\foreach \y/\A in
{0/{Hardware/Software/Bauteil},
1/{System/Fahrzeugbereich},
2/Fahrzeugmodell} {
\path[name path = horiz] (A|-0,\y) -- (B|-0,\y);
\draw[line width = 1pt, name intersections = {of = AC and horiz, by = P},
name intersections = {of = BC and horiz, by = Q}] (P) -- (Q)
node[midway, above] {\A};
}
\node [singleArrow, anchor = east, rotate = 270] at (15,0) {Detailgrad};
\end{tikzpicture}
\end{document}
编辑:添加了一个不同的例子
我怎样才能将三角形和旁边的箭头放在右下角“收费”框的正下方,以使所有内容都对齐?
答案1
我假设你喜欢画下面的图像:
我稍微改变了你的代码:
- 一条通往“屋顶”的路
- 每条水平线一条路径
- 重新计算坐标,使坐标 A 位于 (0,0)
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,
intersections,
positioning, }
\begin{document}
\begin{tikzpicture}[
node distance = 1cm and 1cm,
outer sep = 0]
\coordinate (A) at (0,0);
\coordinate (B) at (8,0);
\coordinate (C) at (4,5);
\draw[name path = AB, line width = 1pt] (A) -- (C) -- (B);
\foreach \y/\T in { 0/{Hardware/Software/Bauteil},
1/{System/Fahrzeugbereich},
2/Fahrzeugmodell} %
{
\path [name path = H] (A |- 0,1.5*\y) -- node [above] {\T} (B |-0,1.5*\y);
\draw[line width = 1pt, name intersections = {of = AB and H, by = {p1\y,p2\y}}]
(p1\y) -- (p2\y);
}
\end{tikzpicture}
\end{document}
附录: 回复您的评论。
- 我必须承认,我不清楚你所说的负坐标是什么意思。
- 所提出的解决方案可以在任何坐标下工作,直到图像构造保证命名路径相交。
- 上述情况意味着,在您的情况下,如果您更改坐标 A、B 和 C(更改为某些负值=,您还需要相应地更改 H 线的位置:
\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,
intersections,
positioning, }
\begin{document}
\begin{tikzpicture}[
node distance = 1cm and 1cm,
outer sep = 0]
\coordinate (A) at (-4,-5); % negative coordinate
\coordinate (B) at ( 4,-5);
\coordinate (C) at ( 0, 0);
\draw[name path = AB, line width = 1pt] (A) -- (C) -- (B);
\foreach \y/\T in { 0/{Hardware/Software/Bauteil},
1/{System/Fahrzeugbereich},
2/Fahrzeugmodell} %
{
\path [name path = H] (A |- 0,-5+1.5*\y) -- % the paths H are move so,
node [above] {\T} (B |- 0,-5+1.5*\y); % that they can intersect path AB
\draw[line width = 1pt, name intersections = {of = AB and H, by = {p1\y,p2\y}}]
(p1\y) -- (p2\y);
}
\end{tikzpicture}
\end{document}