在所附的UML图中有5个类,我想了解类A、B和C的顶部是如何垂直对齐的,而子类保持对齐。请在下面找到我的UML代码和我的截图。
坦克非常感谢你的支持!)
当前的样子:

它应该是什么样子(由油漆编辑的):

UML -代码:
@startuml TestClassDiagram
scale 800 width
skinparam SameClassWidth true
skinparam ClassFontSize 15
class classA {
{field} - attribute1 : int
{field} - attribute2 : int
{method} + method1(void)
{method} + method2(void)
{method} + method3(void)
{method} + method4(void)
{method} + method5(void)
}
class classB {
{field} - attribute1 : int
{field} - attribute2 : int
{method} + method1(void)
{method} + method2(void)
}
class classBchild {
{method} + method1(void)
}
class classC {
{field} - attribute1 : int
{field} - attribute2 : int
{field} - attribute3 : int
{field} - attribute4 : int
{method} + method1(void)
{method} + method2(void)
{method} + method3(void)
{method} + method4(void)
{method} + method5(void)
}
class classCchild {
{method} + method1(void)
}
classB <|-- classBchild
classC <|-- classCchild
@enduml发布于 2021-02-05 16:34:48
在PlantUML中没有一个可以对齐类的特性(还没有)。
如果在所有元素之间添加箭头,可以清楚地看到PlantUML试图做的事情:

它只是从中间对齐所有的图表。
使用这种方法,我们可以创建一个黑客,通过在类定义中填充额外的换行符来实现您想要的结果,直到它们都是相同大小的:

@startuml
skinparam {
SameClassWidth true
ClassFontSize 15
}
class A as "classA" {
{field} - attribute1 : int
{field} - attribute2 : int
__
{method} + method1(void)
{method} + method2(void)
{method} + method3(void)
{method} + method4(void)
{method} + method5(void)
}
class B as "classB" {
{field} - attribute1 : int
{field} - attribute2 : int
__
{method} + method1(void)
{method} + method2(void)
}
class Bc as "classBchild" {
{method} + method1(void)
}
class C as "classC" {
{field} - attribute1 : int
{field} - attribute2 : int
{field} - attribute3 : int
{field} - attribute4 : int
{method} + method1(void)
{method} + method2(void)
{method} + method3(void)
{method} + method4(void)
{method} + method5(void)
}
class Cc as "classCchild" {
{method} + method1(void)
}
B <|-- Bc
C <|-- Cc
@endumlhttps://stackoverflow.com/questions/65211892
复制相似问题