我需要更改 中聚合关系顶部文本的位置pgf-umlcd
。以下是我目前所写的内容:
\begin{figure}[h]
\centering
\begin{tikzpicture}[show background grid]
\begin{class}[text width=10cm]{StateSpace}{7,0}
\attribute{- stateToActionSet: HashMap<State, HashMap<Action, Double>{}>}
\operation{+ addState(s: State)}
\operation{+ size()}
\operation{+ updateQValueForAction(s: State, a: Action, qValue: Double)}
\end{class}
\begin{class}{State}{12,-5}
\attribute{+ latency: Integer}
\attribute{+ isLoadIncreasing: Boolean}
\end{class}
\begin{interface}{Action}{4,-5}
\operation[0]{+ toString()}
\end{interface}
\begin{class}[text width=3cm]{NoAction}{0,-8}
\implement{Action}
\operation{+ toString()}
\end{class}
\begin{class}[text width=3cm]{ScaleIn}{4,-8}
\implement{Action}
\operation{+ toString()}
\end{class}
\begin{class}[text width=3cm]{ScaleOut}{8,-8}
\implement{Action}
\operation{+ toString()}
\end{class}
\aggregation{StateSpace}{states}{1..*}{State}
\aggregation{StateSpace}{actionSet}{1..*}{Action}
\end{tikzpicture}
\caption{State Space Class Diagram}
\end{figure}
如您所见,文本已位于聚合线的顶部。有什么方法可以改变它吗?
答案1
我想说的是,最简单的方法是通过纯 Ti 添加这些钾Z 方法。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage[simplified]{pgf-umlcd}
\begin{document}
\begin{tikzpicture}[show background grid]
\begin{class}[text width=10cm]{StateSpace}{7,0}
\attribute{- stateToActionSet: HashMap<State, HashMap<Action, Double>{}>}
\operation{+ addState(s: State)}
\operation{+ size()}
\operation{+ updateQValueForAction(s: State, a: Action, qValue: Double)}
\end{class}
\begin{class}{State}{12,-5}
\attribute{+ latency: Integer}
\attribute{+ isLoadIncreasing: Boolean}
\end{class}
\begin{interface}{Action}{4,-5}
\operation[0]{+ toString()}
\end{interface}
\begin{class}[text width=3cm]{NoAction}{0,-8}
\implement{Action}
\operation{+ toString()}
\end{class}
\begin{class}[text width=3cm]{ScaleIn}{4,-8}
\implement{Action}
\operation{+ toString()}
\end{class}
\begin{class}[text width=3cm]{ScaleOut}{8,-8}
\implement{Action}
\operation{+ toString()}
\end{class}
\aggregation{StateSpace}{}{}{State}
\aggregation{StateSpace}{}{}{Action}
\path (StateSpace) -- (State) node[midway,sloped,above]{states}
node[midway,sloped,below] {1..*};
\path (StateSpace) -- (Action) node[midway,sloped,above]{actionSet}
node[midway,sloped,below] {1..*};
\end{tikzpicture}
\end{document}