Placing rectangles directly on top of eachother

0 votes
asked Jul 16 in Question / help by Arnold

Hi All,

How can I place rectangles directly on top of eachother? Like this (but with a single line instead of the double line):

My goal is to create a new kind of shape, that I can fill with text and different background colors, that I could use in my diagrams.

I have tried to use class objects, removing the circle, but it is not really similar to what I want.

2 Answers

0 votes
answered Jul 16 by The-Lu (5,860 points)

Hello A.,

  • Would this example be suitable?
@startuml
rectangle r_alias [
rec_1

--

rec_2
]
@enduml


→ See on server

If that can help,
Regards,
Th.

0 votes
answered Jul 18 by Martin

I'm not sure whether your example picture renders properly for me, it looks more like a table of some sort.

But going with your "My goal is to create a new kind of shape, that I can fill with text and different background colors, that I could use in my diagrams."I thought I'd mention this option of PlantUML that lets you create complex shapes by embedding a raw graphviz html node in the PlantUML node.  (I took the example from https://graphviz.org/doc/info/shapes.html)

@startuml
skinparam ComponentStyle rectangle
rectangle n2 [
{{
digraph foo {
    b [shape=none, margin=0
  label=<
<TABLE BGCOLOR="bisque">
  <TR><TD COLSPAN="3">elephant</TD> 
      <TD ROWSPAN="2" BGCOLOR="chartreuse" 
          VALIGN="bottom" ALIGN="right">two</TD> </TR>
  <TR><TD COLSPAN="2" ROWSPAN="2">
        <TABLE BGCOLOR="grey">
          <TR> <TD>corn</TD> </TR> 
          <TR> <TD BGCOLOR="yellow">c</TD> </TR> 
          <TR> <TD>f</TD> </TR> 
        </TABLE> </TD>
      <TD BGCOLOR="white">penguin</TD> 
  </TR> 
  <TR> <TD COLSPAN="2" BORDER="4" ALIGN="right" PORT="there">4</TD> </TR>
</TABLE>>
  ]
}
}}
]
rectangle n3 [
{{
digraph foo {
struct3 [shape=record style=filled, color=yellow, fontcolor=blue, fillcolor=red, label="hello\nworld |{ b |{c|<here> d|e}| f}| g | h"];
}
}}
The 'record' node is simpler
to code, but you can't individually 
colour different boxes.
]
[n1] --> n2
n2 --> n3
@enduml

http://www.plantuml.com/plantuml/png/XL9DZzem4BtxLunysGlR3zXR4sjXMQqgeRBAHks1Sd2IIMBLiLF7AKN0V--axh8HGgebB0_pvhsNfxdll7I-RpJhVYZJIYSRUB1DQmqQ_-Bt6i5XxgMfDBBp2ymKDknmO8Mgd6nhAAs50mCw6MowMhOO6wAOG2DTfKpyWNfQPgZZY4NfVB5wXCNJmtgrJcAUgUvdZrmG94eJ4QLBeCxBy_nBp6TSeCQsbiP7xzEb008DPm0bwsy1DELlP7ajdNVOTyW3DfolyzNd9u9crdlRSFXNEbNLdWk_iu6TxkIg3v8OoOapy-MtL0xtetPW6joAt3ep4e4hc3UQFMfjTrpa_vaGvLK0bOCj0N-xeyZE0hjQUOgyHLFrofoZFVC4WOi45kja-KZ3TnVvmVCwIMFkQtJ4UJUEyjN9O6BBJknqOjln6iskhL7dNP_xsUiY4Tow0hfX6UDIQOt517AhhOj3JXEQCpxya-aUgIPKgDq03fl7wm7ztUoiqmKS3v3HbH-ZmRQ0ueYd8vJqg-08DTz-2dRJ6k4cMBW1Omi4rK6dcbQZOzwIaO84izx3tlQGItFZGPb2_L95BxNU0nkCz0uALPQaP3nazZTsxoY8ZVcuXTjR0MRAp3IyPkmUJT4t-Wy0

Unfortunately I don't think you can get away from the 'box within a box' look.

...