我遇到一个问题,首先从一个节点绘制一条垂直线(附加示例中的红线),然后在某个点处水平绘制到另一个点:
我的代码如下:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,
arrows,
matrix,
chains,
arrows.meta,positioning,
decorations.pathreplacing,
decorations.markings,
intersections,
positioning,
fit}
\tikzstyle{vecArrow} = [thick, decoration={markings,mark=at position
1 with {\arrow[semithick]{open triangle 60}}},
double distance=1.4pt, shorten >= 5.5pt,
preaction = {decorate},
postaction = {draw,line width=1.4pt, white,shorten >= 4.5pt}]
\tikzstyle{innerWhite} = [semithick, white,line width=1.4pt, shorten >= 4.5pt]
\tikzset{
*|/.style={
to path={
(perpendicular cs: horizontal line through={(\tikztostart)},
vertical line through={(\tikztotarget)})
-- (\tikztotarget) \tikztonodes
}
}
}
%% \usepackage{showframe}
\usepackage{amsmath}
\usepackage[linesnumbered,ruled]{algorithm2e}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand{\mygrid}{\tikz{\draw[step=2.5mm] (0,0) grid (2.0,1);}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
\begin{tikzpicture}[
decoration={
markings,
mark=at position 0.5 with {\draw (3pt,2pt) -- (-3pt,-2pt);}
}]
\node[draw,rectangle,minimum height=7mm] (opm3) at (0.0,0.0) {$Op_{-3}$};
\node[draw,rectangle,minimum height=7mm] (opm2) [right=2pt of opm3] {$Op_{-2}$};
\node[draw,rectangle,minimum height=7mm] (opm1) [right=2pt of opm2] {$Op_{-1}$};
\node[draw,rectangle,minimum height=7mm] (opfirst) [right=2pt of opm1] {$Op_{0}$};
\node[draw,rectangle,minimum height=7mm] (oplast) [right=of opfirst] {$Op_{l-1}$};
\node at ($(opfirst)!.5!(oplast)$) {\ldots};
\node[draw,
rectangle,
minimum height=7mm,
minimum width=65mm] (multiplexer) at (2.7,-2.0) {Multiplexer};
\draw[postaction={decorate}] (opm3.south) -- (opm3.south|-multiplexer.north);
\draw[postaction={decorate}] (opm2.south) -- (opm2.south|-multiplexer.north);
\draw[postaction={decorate}] (opm1.south) -- (opm1.south|-multiplexer.north);
\draw[postaction={decorate}] (opfirst.south) -- (opfirst.south|-multiplexer.north);
\draw[postaction={decorate}] (oplast.south) -- (oplast.south|-multiplexer.north);
\node[draw,rectangle,minimum height=7mm] (zaehler1) [right=10mm of multiplexer] {$Z\ddot{a}hler_1$};
\draw[postaction={decorate}] (zaehler1.west) -- (zaehler1.west-|multiplexer.east);
\node[draw,rectangle,minimum height=7mm, minimum width=20mm] (swar) [below=10mm of multiplexer] {OP};
\node [left=2pt of swar] {SWAR};
\node[draw,rectangle,dotted,minimum height=7mm] (versatz) [right=-0.5pt of swar] {Versatz};
\node[draw,rectangle,minimum height=7mm,dotted] (zaehler2) [right=10mm of versatz] {$Z\ddot{a}hler_2$};
\node[draw,rectangle,minimum height=7mm, minimum width=20mm] (swar) [below=10mm of multiplexer] {};
\draw[dotted] (zaehler2.west) -- (zaehler2.west-|versatz.east);
\draw[postaction={decorate}] (swar.north) -- (swar.north|-multiplexer.south);
\node at (2.0,-7.0) {Steuertabelle};
\node at (6.5,-5.0) {Steuersignale};
\node[rectangle, draw, inner sep=0, shift={(5.0,-6.0)}] (stol) {\mygrid};
\node[rectangle, draw, inner sep=0, shift={(8.0,-6.0)}] (stor) {\mygrid};
\node at ($(stol)!.5!(stor)$) {\ldots};
\node[rectangle, draw, inner sep=0, shift={(5.0,-8.0)}] (stul) {\mygrid};
\node[rectangle, draw, inner sep=0, shift={(8.0,-8.0)}] (stur) {\mygrid};
\node at ($(stul)!.5!(stur)$) {\ldots};
\node at ($(stol)!.5!(stul)$) {\vdots};
\node at ($(stor)!.5!(stur)$) {\vdots};
\draw[thick,black] (4.0,-6.0) node (op) {} -- (6.0,-6.0) -- (6.0,-5.75) -- (4.0,-5.75) --(4.0,-6.0);
\draw[thick,black] (7.0,-6.0) -- (9,-6.0) -- (9.0,-5.75) -- (7.0,-5.75) --(7.0,-6.0);
\draw[thick,red,-{Latex[width=1mm]}] (swar.south) -- (4.0,-5.9);
\end{tikzpicture}
\end{document}
任何想法都值得赞赏。
谢谢马塞尔
答案1
为了娱乐和锻炼(因为你的问题已经被解决了鲍勃·鲍勃评论) ...
在姆韦下面我从你的所有不必要的锚扩展中删除,定义一些新的样式,使代码更短,所有元素都相对于彼此定位。顺便说一句,加载每个 tikz 库就足够了 :-)
也许您会发现建议的解决方案很有用:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta,
calc,
decorations.markings,
positioning,
}
\begin{document}
\begin{tikzpicture}[
node distance = 8mm and 10mm,
box/.style = {draw, minimum height=7mm, outer sep=0mm},
ebox/.style = {% emphesize box
draw, thick, inner sep=0mm,
minimum height=2.5mm, minimum width=20mm},
DL/.style = {% Decorated Line
decoration={markings,
mark=at position 0.5 with
{\draw (3pt,2pt) -- (-3pt,-2pt);}},
postaction={decorate}},
mygrid/.style = {inner sep=0mm,
minimum height=10mm, minimum width=20mm,
node contents={},
path picture={%
\draw[step=2.5mm] (path picture bounding box.south west) grid + (2,1);
}
},
shrtdot/.style = {thick, dotted, shorten > =2.2mm, shorten <=2.2mm}
]
\node[box] (opm3) {$Op_{-3}$};
\node[box] (opm2) [right=2pt of opm3] {$Op_{-2}$};
\node[box] (opm1) [right=2pt of opm2] {$Op_{-1}$};
\node[box] (opfirst) [right=2pt of opm1] {$Op_{0}$};
\node[box] (oplast) [right=of opfirst] {$Op_{l-1}$};
\draw[shrtdot] (opfirst) -- (oplast);
\node[box, minimum width=65mm] (multiplexer) at (2.7,-2.0) {Multiplexer};
\draw[DL] (opm3) -- (opm3 |- multiplexer.north);
\draw[DL] (opm2) -- (opm2 |- multiplexer.north);
\draw[DL] (opm1) -- (opm1 |- multiplexer.north);
\draw[DL] (opfirst) -- (opfirst |- multiplexer.north);
\draw[DL] (oplast) -- (oplast |- multiplexer.north);
\node[box,right=of multiplexer] (zaehler1) {$Z\ddot{a}hler_1$};
\draw[DL] (zaehler1) -- (multiplexer);
\node[box, minimum width=20mm,
below=of multiplexer] (swar) {OP};
\node [left=2pt of swar] {SWAR};
\node[box,dotted,
right=0mm of swar] (versatz) {Versatz};
\node[box,dotted,
right=of versatz] (zaehler2) {$Z\ddot{a}hler_2$};
\draw[shrtdot] (zaehler2) -- (versatz);
\draw[DL] (multiplexer) -- (swar);
\node (stol) [mygrid, below right=of swar];
\node (stor) [mygrid, right=of stol];
\draw[shrtdot] (stol) -- (stor);
\node [above=1mm of $(stol.north)!0.5!(stor.north)$] (6.5,-5.0) {Steuersignale};
\node (stul) [mygrid, below=of stol];
\node (stur) [mygrid, below=of stor];
\draw[shrtdot] (stul) -- (stur);
\node [left=of $(stol)!0.5!(stul)$] {Steuertabelle};
\draw[shrtdot] (stol) -- (stul);
\draw[shrtdot] (stor) -- (stur);
\node (a) [ebox,above] at (stol.center) {};
\node [ebox,above] at (stor.center) {};
\draw[thick,red,-Latex] (swar) |- (a);
\end{tikzpicture}
\end{document}
答案2
bobbyandbob 提出的解决方案(参见评论)非常有效:
\draw[thick,red,-{Latex[width=1mm]}] (swar.south) |- (4.0,-5.9);
答案3
提供更多手动控制的解决方案使用命令\coordinate
。“肘部”的位置位于坐标 (2.7,-5.9)。因此代码
\coordinate(elbow) at (2.7,-5.9);
\draw[thick,red,-{Latex[width=1mm]}] (swar.south) -- (elbow) -- (4.0,-5.9);
将产生输出:
改变肘部的坐标
\coordinate(elbow) at (2.0,-5.9);
\draw[thick,red,-{Latex[width=1mm]}] (swar.south) -- (elbow) -- (4.0,-5.9);
产生更多的弯曲: