![TikZ-UML 的相对定位不起作用](https://linux22.com/image/422434/TikZ-UML%20%E7%9A%84%E7%9B%B8%E5%AF%B9%E5%AE%9A%E4%BD%8D%E4%B8%8D%E8%B5%B7%E4%BD%9C%E7%94%A8.png)
为了创建 TikZ 组件图,我使用 TikZ-UML (https://perso.ensta-paris.fr/~kielbasi/tikzuml/index.php?lang=en&id=download)。对于相对定位,我将umlbasiccomponent
s 定位为right=1.5cm of component-body.east
(如中所述) Tikz UML 相对定位问题)。虽然组件本身对齐正确,但标题对齐错误,如下所示:
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{tikzpeople}
\usepackage{tikz-uml}
\usetheme[compress]{Berlin}
\begin{document}
\begin{frame}{Komponenten}
\begin{tikzpicture}
\begin{umlcomponent}[name=peass]{Peass}
\umlbasiccomponent[anchor=west, name=dependency, fill=white]{Dependency}
\umlbasiccomponent[right=1.5cm of dependency-body.east, name=measurement, fill=white]{Measurement}
\end{umlcomponent}
\end{tikzpicture}
\end{frame}
\end{document}
有没有什么方法可以正确对齐文本和组件的框架?
答案1
一个(不太好的)解决方案是使用 umldocument (https://github.com/maybeec/tikz-uml-component-diagram.git),这样可以轻松实现相对定位:
\documentclass{beamer}
\definecolor{SeaGreen}{rgb}{0.0,0.8,0.1}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\usepackage{tikz}
\usetikzlibrary{
arrows.meta,
shapes,
positioning,
calc,
decorations.markings,
decorations.pathreplacing,
decorations.text,
decorations.pathmorphing,
decorations.shapes
}
\usepackage{umldocument}
\usepackage{umlmultidocument}
\usepackage{umlcomponent}
\usetheme[compress]{Berlin}
\tikzset{
doc/.style={umldocument, align=center, text width=1.5cm, minimum height=2.5cm},
multdoc/.style={umlmultidocument, align=center, text width=1.5cm, minimum height=2.5cm},
comp/.style={umlcomponent, align=center, text width=2cm, minimum height=1.0cm},
comment/.style={umldocument,fill=SeaGreen, text width=1.7cm, minimum height=.7cm}
}
\begin{document}
\begin{frame}
\begin{tikzpicture}
\node[comp] (dependency) {Dependency};
\node[right=of dependency, comp] (measurement) {Measurement};
\node[right=of measurement, comp] (analysis) {Analysis};
\node[comp, right=-0.5cm of dependency.west, minimum width=10cm, fill opacity=0.0, text opacity=1.0, text depth=1.5cm] (peass) {Peass};
\end{tikzpicture}
\end{frame}
\end{document}
其结果是:
由于这不是一个确切的解决方案,我将接受使用 tikz-uml 和/或保留拆分组件的解决方案,但就目前而言,这是一个可行的解决方法。