TikZ:用水平线连接一个矩形并用点标记交点

TikZ:用水平线连接一个矩形并用点标记交点

我正在努力解决如何在不使用绝对坐标的情况下连接矩形节点和垂直线的问题。两条线的交点应该用点标记。我强烈地感觉到一定有更优雅的方法来实现这一点。

谢谢马塞尔

\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}

结果和以前一样。

在此处输入图片描述

相关内容