\onehalfspacing 破坏列表中的 tikz

\onehalfspacing 破坏列表中的 tikz

这是一个永无止境的故事。我想做一些代码注释。最后,我得到了我的宏,但是现在……

列表中的 tikz 绘图在某些情况下会中断(靠近分页符):

    \documentclass{article}

    \usepackage{blindtext}
    \usepackage{relsize}
    \usepackage{setspace}
    \usepackage{tikz}
    \usepackage{listings}
    \usetikzlibrary{decorations.pathreplacing,calc,arrows}
    \newcommand*\circled[1]{\tikz[baseline=(char.base)]{%
                \node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
    \newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
    \newcommand*{\AddNote}[5]{%
    \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};
    \end{tikzpicture}%
    }

    \begin{document}

    \blindtext
    \blindtext

    \onehalfspacing
    \begin{lstlisting}[escapechar=+, caption=Muh, label=lst:oop, language=c]
    +\linespread{2}+
    .. 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}+
    }
    \end{lstlisting}
    \AddNote{valid}{8}{0}{Validation}{right}%

    \AddNote{auth}{8}{0}{Authorization}{right}%

    \AddNote{log0}{13.8}{-1}{Logging}{left}%
    \AddNote{log1}{13.8}{3}{}{}%
    \AddNote{log2}{13.8}{4}{}{}%

    \AddNote{lock0}{12}{-1}{Threading}{left}%
    \AddNote{lock1}{12}{2}{}{}%
    \AddNote{lock2}{12}{3}{}{}%

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

    \blindtext

    \end{document}

答案1

嗯,在列表外部使用也存在问题(它会破坏标题背景\baselinestretch)。\onehalfspacing

这是我的想法:将列表放在图中并\onehalfspacing在列表定义中使用,例如:

\begin{lstlisting}[basicstyle=\ttfamily\footnotesize\onehalfspacing....]

相关内容