
我正在努力解決如何在不使用絕對座標的情況下連接矩形節點和垂直線的問題。兩條線的交點應用點標記。我有一種強烈的感覺,一定有一種更優雅的方式來實現這一點。
謝謝馬塞爾
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,positioning,decorations.pathreplacing}
\usetikzlibrary{intersections}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\draw[thick] (-4,10) node (dpdata) [above] {Data} -- (-4,0);
\node[ draw,
align=center,
left=of dpdata,
yshift=-4cm,
minimum width=2cm,
minimum height=3cm,
] (ram) {Transient \\ Memory \\ (RAM)};
\node[ draw,
align=center,
above=of ram,
minimum width=1.5cm,
minimum height=1cm
] (mar) {MAR};
\node[ draw,
align=center,
below=of ram,
minimum width=1.5cm,
minimum height=1cm
] (mdr) {MDR};
\draw[color=blue,thick] (mar.east) -- (-4,9.25);
\fill (-4,9.25) circle [radius=2pt];
\draw[color=blue,thick] (mdr.east) -- (-4,3.25);
\fill (-4,3.25) circle [radius=2pt];
\draw[color=blue,thick] (mdr.north) -- (ram.south);
\draw[color=blue,thick] (mar.south) -- (ram.north);
\end{tikzpicture}
\end{figure}
\end{document}
答案1
只要所有的點和連接都在矩形網格上,您就可以使用這種簡單而優雅的語法來提取座標(我舉一個簡單的例子):
\begin{tikzpicture}
\path
(0,0) node[draw] (joe) {Joe}
(2,2) node[draw] (blow) {Blow};
;
\draw[blue] (joe -| blow) circle (2pt);
\end{tikzpicture}
操作-|
員將從第一個點 (joe) 中提取 x 座標,並從第二個點 (blow) 中提取 y 座標。
答案2
像這樣?
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, chains, intersections, positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 9mm,
start chain = going below,
box/.style = {rectangle, draw,
text width=22mm, align=center, inner sep=2mm,
on chain}
]
\node (mar) [box] {MAR};
\node (ram) [box] {Transient Memory (RAM)};
\node (mdr) [box] {MDR};
%
\coordinate[above right=of mar] (data);
\draw[thick, name path=A] (data) node[above] {Data} -- + (0,-4);
\path[overlay,name path=B] (mar) -- ++ (3,0);
\path[overlay,name path=C] (mdr) -- ++ (3,0);
%
\draw[color=blue,thick,fill,
name intersections={of=A and B, by={a}}]
(mar) -- (a) circle (2pt);
\draw[color=blue,thick,fill,
name intersections={of=A and C, by={b}}]
(mdr) -- (b) circle (2pt);
\draw[color=blue,thick] (mar) -- (ram) (ram) -- (mdr);
\end{tikzpicture}
\end{document}
附錄: 提供更簡單的解決方案邁克爾·帕爾默回答。如果你採用上面的MWE,你可以簡單的寫:
\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, chains, intersections, positioning}
\begin{document}
\begin{tikzpicture}[
node distance = 3mm and 9mm,
start chain = going below,
box/.style = {rectangle, draw,
text width=22mm, align=center, inner sep=2mm,
on chain}
]
\node (mar) [box] {MAR};
\node (ram) [box] {Transient Memory (RAM)};
\node (mdr) [box] {MDR};
%
\coordinate[above right=of mar] (data);
\draw[thick] (data) node[above] {Data} -- + (0,-4);% changed
\draw[color=blue,thick,fill]
(mar) -- (mar -| data) circle (2pt)% changed
(mdr) -- (mdr -| data) circle (2pt)% changed
(mar) -- (ram)
(ram) -- (mdr);
\end{tikzpicture}
\end{document}
結果和以前一樣。