如何使用 pgf-umlsd 轻松地注释 callself?

如何使用 pgf-umlsd 轻松地注释 callself?

我想绘制一个带有pgf-umlsd包的序列图。我想对某些调用和消息的时间点和持续时间进行一些注释。这对于调用和消息很有效 - 但我不知道如何标记自调用(callself)的起点和终点。有人能告诉我如何“获取”这些点吗?

以下是我正在尝试做的 MWE:

\documentclass{standalone}
\usepackage{pgf-umlsd}
\usetikzlibrary{calc,decorations.pathreplacing}

\begin{document}

    \begin{sequencediagram}
        \newthread{a}{A}
        \newinst{b}{B}
        
        % Annotating a message works
        \mess{a}{msg}{b}
        \node[anchor=east](t0)at(mess from){$t_0$};
        \node[anchor=west](t0)at(mess to){$t_1$};

        \postlevel % for better readability
        
        % Annotating a call works
        \begin{call}{a}{c()}{b}{rc} \end{call}
        \node[anchor=east]at(cf1){$t_2$};
        \node[anchor=west]at(ct1){$t_3$};
        \node[anchor=west]at(rt1){$t_4$};
        \node[anchor=east]at(rf1){$t_5$};
        \draw [decorate, 
            decoration = {brace,
            raise=13pt,
            amplitude=3pt}]%
            let
                \p1=(ct1),
                \p2=(rt1)
            in
                (\x2,\y1) -- (\p2)
            node[pos=0.5,right=13pt]{$\Delta t_{34}$};

        \postlevel % for better readability
        
        % Annotating a selfcall does not work :(
        \begin{callself}{a}{cs()}{rcs} \end{callself}
        % These are placed on the previous call annotations:
        % \node[anchor=east]at(cf1){$t_6$};
        % \node[anchor=west]at(ct1){$t_7$};
        % \node[anchor=west]at(rt1){$t_8$};
        % \node[anchor=east]at(rf1){$t_9$};
        % \draw [decorate, 
        %     decoration = {brace,
        %     raise=13pt,
        %     amplitude=3pt}]%
        %     let
        %         \p1=(ct1),
        %         \p2=(rt1)
        %     in
        %         (\x2,\y1) -- (\p2)
        %     node[pos=0.5,right=13pt]{$\Delta t_{69}$};
        
    \end{sequencediagram}
\end{document}

结果如下(我想添加的注释用红色粗略标记): 生成的 PDF

答案1

欢迎来到 TeX.SX!为了获得这些坐标,您必须深入研究包的源代码。有些坐标甚至没有名称,因此您需要根据包中路径的定义进行一些移动。

您想要放置“t_9”的坐标恰好位于([xshift=0.8cm, yshift=-0.33*\unitfactor cm]sce1)。但是,我通过额外的移动改变了标签以及括号的位置,因为否则标签和括号会与“rcs”的标签重叠。

\documentclass{standalone}
\usepackage{pgf-umlsd}
\usetikzlibrary{calc,decorations.pathreplacing}

\begin{document}

    \begin{sequencediagram}
        \newthread{a}{A}
        \newinst{b}{B}
        
        % Annotating a message works
        \mess{a}{msg}{b}
        \node[anchor=east](t0)at(mess from){$t_0$};
        \node[anchor=west](t0)at(mess to){$t_1$};

        \postlevel % for better readability
        
        % Annotating a call works
        \begin{call}{a}{c()}{b}{rc} \end{call}
        \node[anchor=east] at (cf1) {$t_2$};
        \node[anchor=west] at (ct1) {$t_3$};
        \node[anchor=west] at (rt1) {$t_4$};
        \node[anchor=east] at (rf1) {$t_5$};
        \draw [decorate, 
            decoration = {brace,
            raise=13pt,
            amplitude=3pt}]%
            let
                \p1=(ct1),
                \p2=(rt1)
            in
                (\x2,\y1) -- (\p2)
            node[pos=0.5,right=13pt]{$\Delta t_{34}$};

        \postlevel % for better readability
        
        \begin{callself}{a}{cs()}{rcs} \end{callself}
        \node[anchor=east] at (sc1) {$t_6$};
        \node[anchor=west] at ([xshift=0.8cm]scb1) {$t_7$};
        \node[anchor=east] at (sct1){$t_8$};
        % coordinate for t9 is exactly at ([xshift=0.8cm, yshift=-0.33*\unitfactor cm]sce1)
        \node[anchor=west] at ([xshift=0.8cm, yshift=-0.35cm]sce1) {$t_9$};
        \draw [decorate, 
             decoration = {brace,
             raise=13pt,
             amplitude=3pt}]%
             let
                 \p1=(sc1),
                 \p2=([xshift=1cm, yshift=-0.33*\unitfactor cm]sce1)
             in
                 (\x2,\y1) -- (\p2)
             node[pos=0.5,right=13pt]{$\Delta t_{69}$};

    \end{sequencediagram}
    
\end{document}

在此处输入图片描述

相关内容