如何将垂直点放在水平线的上方和下方并居中

如何将垂直点放在水平线的上方和下方并居中

在我的内存布局图中,我希望在轮廓内存单元的上方和下方有三个垂直点。

有没有更优雅的方法来计算周围的水平和垂直线?

提前致谢

马塞尔

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}

\begin{document}

\begin{tikzpicture}

\node[draw,rectangle,minimum height=7mm] (opc)              {Operations};
\node[draw,rectangle,minimum height=7mm,minimum width=15mm] (operanda) [right=0pt of opc]  {$\#42$};
\node[draw,rectangle,minimum height=7mm,minimum width=15mm] (operandb) [right=0pt of operanda] {$\$1000$};
\node[draw,rectangle,minimum height=7mm,minimum width=15mm] (operandc) [right=0pt of operandb] {$\$2000$};

\draw[red,thick] (-0.95,0.35) -- (5.5,0.35);
\draw[red,thick] (-0.95,-0.35) -- (5.5,-0.35);

\draw[red,thick] (-0.95,2.0) -- (-0.95,-2.0);
\draw[red,thick] (5.5,2.0) -- (5.5,-2.0);

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

只是猜测:

在此处输入图片描述

至少代码更短了......

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{chains, fit, positioning}

\begin{document}
    \begin{tikzpicture}[
    node distance = 0pt,
      start chain = A going right,
      base/.style = {draw,rectangle,minimum height=7mm, outer sep=0pt},
       box/.style = {base,minimum width=15mm, on chain=A},
dottedline/.style = {ultra thick, loosely dotted,shorten >=1mm, shorten <=1mm}
                    ]    
\node[base, on chain=A] (opc)       {Operations};
\node[box] (operanda)   {$\#42$};
\node[box] (operandb)   {$\$1000$};
\node[box] (operandc)   {$\$2000$};
%
\node[draw=red,thick,inner sep=0pt, fit=(A-1) (A-4)]  (operand) {};% <-- added missing node name
%
\draw[dottedline] (operand.north) -- + (0, 7mm);
\draw[dottedline] (operand.south) -- + (0,-7mm);
    \end{tikzpicture}
\end{document}

编辑:ups,在姆韦不是最后一个(生成图像的)...其中缺少红框的名称。现在已经纠正。

相关内容