PlantUML中能否实现箭头标签自动换行?
解决PlantUML状态图箭头标签自动换行问题
你用arrow选择器添加WordWrap样式的方式无效,是因为当前PlantUML版本中,WordWrap属性并不支持作用于箭头的标签元素。下面提供两种可行的解决办法:
方法一:全局设置自动换行宽度
通过skinparam wrapWidth可以全局控制所有文本标签的自动换行阈值,数值代表触发换行的字符宽度上限。修改后的完整代码示例:
@startuml skin rose left to right direction skinparam wrapWidth 20 <style> arrow { fontcolor #green } </style> state a state b [*] -> a a -> b : very long status transition description that I want to be wrapped but it won't despite I try to use styling for arrow and it affects the arrow label font color b -> [*] @enduml
方法二:手动插入换行符
如果需要精准控制换行位置,直接在标签文本中插入\n手动拆分内容:
@startuml skin rose left to right direction <style> arrow { fontcolor #green } </style> state a state b [*] -> a a -> b : very long status transition\n description that I want to be wrapped\n but it won't despite I try to use\n styling for arrow and it affects\n the arrow label font color b -> [*] @enduml
两种方法都能保留你原来设置的箭头标签字体颜色,按需选择即可。
内容的提问来源于stack exchange,提问作者OK3
相关产品推荐
相关产品推荐

