You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何为PlantUML类图中的各类别单独设置样式?

PlantUML中为单个类别单独设置样式

当然可以为各类别单独设置样式,无需全局统一应用。你只需要在<style>块中,把原来的通用class选择器替换为具体的类别名称(比如interface、enum、annotation等),就能让样式只对目标类别生效。

示例1:仅调整Interface的样式

@startuml

<style>
  classDiagram {
    interface {
      FontColor darkgreen
      BackgroundColor lightgreen
      header {
        FontSize 18
        FontStyle italic
        FontColor green
      }
    }
  }
</style>

abstract        abstract
abstract class  "abstract class"
annotation      annotation
class           class
class           class_stereo  <<stereotype>>
entity          entity
enum            enum
exception       exception
interface       interface
metaclass       metaclass
protocol        protocol
stereotype      stereotype
struct          struct

@enduml

示例2:为多个类别分别设置不同样式

如果需要同时给多个类别单独配置,直接在classDiagram下添加多个类别选择器即可:

@startuml

<style>
  classDiagram {
    interface {
      FontColor darkgreen
      BackgroundColor lightgreen
    }
    enum {
      FontColor darkblue
      BackgroundColor lightblue
      header {
        FontStyle bold
      }
    }
    annotation {
      BackgroundColor pink
      FontColor red
    }
  }
</style>

abstract        abstract
abstract class  "abstract class"
annotation      annotation
class           class
class           class_stereo  <<stereotype>>
entity          entity
enum            enum
exception       exception
interface       interface
metaclass       metaclass
protocol        protocol
stereotype      stereotype
struct          struct

@enduml

这种方式下,只有指定的类别会应用自定义样式,其余类别保持PlantUML的默认样式。

内容的提问来源于stack exchange,提问作者Corbie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.07 06:48:10