It's a never-ending story I have to tell. I want to make some code annotations. Finally, I got my macro, but now...

The tikz drawings in listings break in certain circumstances (near page break):


                \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
    \newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
    \begin{tikzpicture}[overlay, remember picture]
    \coordinate (x) at (#2,0);
    \coordinate (a) at ($(x)!(#1.north)!($(x)+(0,1)$)$);
    \coordinate (b) at ($(a)+(0.8,0)$);
    \coordinate (c) at ($(b)+(0,#3)$);
    \draw [open triangle 45-] (a) -- (b) -- (c);
    \node[#5] at (c) {\bf\sffamily\smaller#4};



    \begin{lstlisting}[escapechar=+, caption=Muh, label=lst:oop, language=c]
    .. Core members+\tikzmark{core0}+
    .. Log stream+\tikzmark{log0}+
    .. +\color{black}{Lock object}\tikzmark{lock0}+

    public void Method (object[] args)
      .. Check arguments+\tikzmark{valid}+
      .. Ensure authorization+\tikzmark{auth}+
      .. Lock +\color{black}{object for}+ thread safety+\tikzmark{lock1}+
      .. Start transaction+\tikzmark{trans1}+
      .. Log start of operation+\tikzmark{log1}+
      .. Perform core operation+\tikzmark{core1}+
      .. Log completion of operation+\tikzmark{log2}+
      .. Commit or rollback transaction+\tikzmark{trans2}+
      .. Unlock +\color{black}{object}\tikzmark{lock2}+




    \AddNote{trans1}{10.2}{-1}{Transaction}{above left}%



Well, there was also a problem with using \baselinestretch and \onehalfspacing outside the listing (it blow up the caption background).

Here is what I came up with: Put the listing in a figure and use \onehalfspacing in the listing definition, like:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.