协议消息图 - 矩形 - 02

协议消息图 - 矩形 - 02

我尝试编译此先前答案中建议的代码

协议消息图-矩形

\documentclass{article}
\usepackage[margin=12mm]{geometry}
\usepackage{hyperref}
\usepackage[underline=true]{pgf-umlsd}
\usetikzlibrary{calc}
\begin{document}
\begin{sequencediagram}
\newinst{ue}{UE}
\newinst[3]{nodeb}{Node B}
\newinst[3]{rnc}{RNC}
\mess{ue}{RRC Connection Request}{rnc}
\mess{rnc}{Radio Link Setup Request}{nodeb}
\mess{nodeb}{Radio Link Setup Response}{rnc}
\mess{rnc}{Establish Request}{nodeb}
\mess{nodeb}{Establish Confirm}{rnc}
\mess{rnc}{RRC Connection Setup}{ue}
\postlevel
\mess{nodeb}{Synchronization Indication}{rnc}
\filldraw[fill=black!30] ($(RRC Connection Setup to)+(0,-.3)$) rectangle ($(Synchronization Indication from) +(0,.3)$)
node[midway] {L1 Synchronization};
\mess{ue}{RRC Connection Setup Complete}{rnc}
\begin{pgfonlayer}{umlsd@background}
\fill[red!30, rounded corners]
($(RRC Connection Request from)+(-1ex,1.5em)$) rectangle ($(RRC Connection Setup Complete to)+(1ex, -1.5ex)$);
\end{pgfonlayer}
\end{sequencediagram}
\end{document}

我收到此错误:

! Package pgf Error: Sorry, the requested layer 'umlsd@background' is not part
of the layer list. Please verify that you provided \pgfsetlayers and that 'umls
d@background' is part of this list.

我使用的软件包pgf-umlsd是最新版本 0.7

谢谢

答案1

@字符需要定义为字母。您可以定义一个新的范围键:on umlsd background

\documentclass{article}
\usepackage[margin=12mm]{geometry}
\usepackage{hyperref}
\usepackage[underline=true]{pgf-umlsd}
\makeatletter
\tikzset{
  on umlsd background/.style={
    execute at begin scope={
      \pgfonlayer{umlsd@background}
      \let\tikz@options=\pgfutil@empty%
      \tikzset{#1}%
      \tikz@options
    },
    execute at end scope={\endpgfonlayer},
  }
}
\makeatother
\usetikzlibrary{calc}

\begin{document}
\begin{sequencediagram}
\newinst{ue}{UE}
\newinst[3]{nodeb}{Node B}
\newinst[3]{rnc}{RNC}
\mess{ue}{RRC Connection Request}{rnc}
\mess{rnc}{Radio Link Setup Request}{nodeb}
\mess{nodeb}{Radio Link Setup Response}{rnc}
\mess{rnc}{Establish Request}{nodeb}
\mess{nodeb}{Establish Confirm}{rnc}
\mess{rnc}{RRC Connection Setup}{ue}
\postlevel
\mess{nodeb}{Synchronization Indication}{rnc}
\filldraw[fill=black!30] ($(RRC Connection Setup to)+(0,-.3)$) rectangle ($(Synchronization Indication from) +(0,.3)$)
node[midway] {L1 Synchronization};
\mess{ue}{RRC Connection Setup Complete}{rnc}
\begin{scope}[on umlsd background]
  \fill[red!30, rounded corners]($(RRC Connection Request from)+(-1ex,1.5em)$) rectangle ($(RRC Connection Setup Complete to)+(1ex, -1.5ex)$);
\end{scope}
\end{sequencediagram}
\end{document}

相关内容