TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question
This smells similar to the issue raised in tex.stackexchange.com/q/49599/86 – Loop Space Dec 10 '12 at 23:27

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:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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