How to align blocks in PlantUML class diagrams?

No, there's no way to do that, sorry :( The idea behind PlantUML is that you should not care too much about the layout rendering.

Actually, early versions of PlantUML use to align classes, but it was an issue: When there were many unrelated classes, diagrams tended to be very large and very thin. So a patch was added to organize classes in a square.

How many classes do you want to have in your diagram? Sure it would be possible to disable the organizing patch for e.g. 3 to 5 classes. You could post a suggestion to the forum to see what other users think about it.


Using a -[hidden] relation can do the job :

@startuml  
class Bob  
class Alice  
class Dan  
class Foo
class Bar
class Foobar

Bob -[hidden] Alice
Bar -[hidden] Foobar
@enduml

http://www.plantuml.com/plantuml/png/Iyv9B2vMSCfFKb3WIWQp7NCoarFXF9V4F3ZRBJyVod9AB4A89G4vN20JTACpCbDIKlDY8MPm0LKXYK5K0W00


UPDATES Aug.08.2019

From Rotsiser's comment, by combining changing the length of lines with together keyword, it can align elements

@startuml
class A
A ..> B
C ---> B
D ...> B
together {
    class E
    class F
    class G
}
E ----> B
@enduml

enter image description here


OUTDATED

You are able to align elements by changing the number of line's character, such as '-', '.', and so on.

@startuml
class A
A ..> B
C ---> B
D ...> B
E ----> B
F ----> B
G ----> B
@enduml

enter image description here


Here is a solution.

The documentation: "It is also possible to change arrow direction by adding left, right, up or down keywords inside the arrow:"

@startuml
foo -left-> dummyLeft 
foo -right-> dummyRight 
foo -up-> dummyUp 
foo -down-> dummyDown
@enduml

enter image description here

To your question:

@startuml
class Bob
class Alice
class Dan
Alice -left[hidden]-> Bob
Alice -right[hidden]-> Dan 
@enduml

enter image description here

It may also be useful:

@startuml
class Bob
class Alice
class Dan
Bob -right-|> Alice
Alice -right-> Dan
interface Friend
Dan -up..> Friend
interface Person
Friend -left-> Person
interface Object
Person -down-> Object
interface Native
Object -right-> Native
@enduml

enter image description here

Tags:

Uml

Plantuml