Tikz 覆盖未按预期工作

Tikz 覆盖未按预期工作

我正在使用 pdflatex 将以下代码转换为 pdf,但没有得到预期的覆盖。

\begin{lstlisting}[language=nasm,style=nasm, escapeinside={<>}]
CodeVersion1:   push    ax      <\tikz[remember picture, overlay] \node[circle,fill=red!50] (a) {};> 
                push    bx

                mov     ax, bx
                add     ax, bx
                ; some more code

                pop     bx
                pop     ax
                ret

MeasureSize CodeVersion1        <\tikz[remember picture, overlay] \node [circle,fill=red!50] (b) {};> 

CodeVersion2:   push    ax      <\tikz[remember picture, overlay] \node [circle,fill=red!50] (c) {};> 
                push    bx

                mov     ax, bx
                sub     ax, bx
                ; some more code

                pop     bx
                pop     ax
                ret

MeasureSize CodeVersion2        <\tikz[remember picture, overlay] \node [circle,fill=red!50] (d) {};> 

SomeLabel:      push    ax, cx  <\tikz[remember picture, overlay] \node [circle,fill=red!50] (e) {};> 

                mov     ax, bx
                add     ax, bx
                sub     ax, bx
                ; some more code

                pop     ax, cx
                ret

MeasureSize SomeLabel           <\tikz[remember picture, overlay] \node [circle,fill=red!50] (f) {};> 
\end{lstlisting}
\begin{tikzpicture} 
    [
    remember picture,
    overlay,
    brace/.style = {
        decorate,
        decoration={
            brace,
            amplitude=5pt,
            mirror
        }
    }
    ]

    \draw[brace] (a) grid (b);
    \draw[brace] (c) grid (d);
    \draw[brace] (e) grid (f);

\end{tikzpicture}

我想从一个读点到下一个读点绘制括号,但我得到的图片看起来像这样:

在此处输入图片描述

我是否遗漏了什么?

答案1

使用--而不是grid。我不知道具体发生了什么,但grid无论如何,该操作并不是为了在点之间画直线,如果你尝试的话,\draw (a) grid (b);你会发现这也发生了位移。

代码输出

\documentclass{article}
\usepackage{tikz,listings}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{lstlisting}[escapeinside={<>}]
CodeVersion1:   push    ax      <\tikz[remember picture, overlay] \node[circle,fill=red!50] (a) {};> 
                push    bx

                mov     ax, bx
                add     ax, bx
                ; some more code

                pop     bx
                pop     ax
                ret

MeasureSize CodeVersion1        <\tikz[remember picture, overlay] \node [circle,fill=red!50] (b) {};> 

CodeVersion2:   push    ax      <\tikz[remember picture, overlay] \node [circle,fill=red!50] (c) {};> 
                push    bx

                mov     ax, bx
                sub     ax, bx
                ; some more code

                pop     bx
                pop     ax
                ret

MeasureSize CodeVersion2        <\tikz[remember picture, overlay] \node [circle,fill=red!50] (d) {};> 

SomeLabel:      push    ax, cx  <\tikz[remember picture, overlay] \node [circle,fill=red!50] (e) {};> 

                mov     ax, bx
                add     ax, bx
                sub     ax, bx
                ; some more code

                pop     ax, cx
                ret

MeasureSize SomeLabel           <\tikz[remember picture, overlay] \node [circle,fill=red!50] (f) {};> 
\end{lstlisting}
\begin{tikzpicture} 
    [
    remember picture,
    overlay,
    brace/.style = {
        decorate,
        decoration={
            brace,
            amplitude=5pt,
%            mirror
        }
    }
    ]

    \draw[brace] (a) -- (b);
    \draw[brace] (c) -- (d);
    \draw[brace] (e) -- (f);

\end{tikzpicture}

\end{document}

相关内容