Splitting a canvas with different size

Hi, I want to split a canvas into 4 blocks. I see an example in here:
https://root.cern.ch/root/html/tutorials/graphs/zones.C.html
However I want the first row to take 80% and 2nd row to take 20% of the space.
Also there should not be any space left in between two rows.
Any help?

The zones.C example uses TPad::Divide().
This method is a quick way to split a canvas in equal areas. If your Pads’ layout is not equally space you should create the pads yourself at the positions you need.

Hi, thank you for quick response. I tried the following way:
In one canvas, I put TPad1 and split it into 2 subTPads.
So I have TPad11 + TPad12 side by side.
Then I put TPad2 and split it in 2 subTPads.
Now I have TPad21+TPad22 side by side but this TPad21+TPad22 remains only below TPad12.
My desired format is:
TPad11+TPad12(80%)
TPad21+TPad22(20%)

One possible solution is to define 4 such TPads. But I was wondering whether it is possible to use two TPads each divided into two or by canvas splitting.

The solution you end up with looks fine.
I am not sure I understand what is the problem now.
The ratio (80%, 20%) is along the Y axis (vertically) ?

Yes the ratio is along Y-axis.
With 4 defined TPads there is no problem, but if I want to use 2 TPads each splitted into 2, then there is problem.
I want to place TPad21+TPad22 below the TPad11+TPad12.


| 0000000000000000000000 | 000000000000000000000000000 |
| 0000000 TPad11 00000000 | 0000000 TPad12 000000000000 |
| 0000000000000000000000 | 000000000000000000000000000 |

| 0000000 TPad21 00000000 | 0000000 TPad22 000000000000 |

But if I define only 2 TPads and each one is splitted into 2 more then its coming as follow:

| 0000000000000000000000 | 000000000000000000000000000 |
| 0000000 TPad11 00000000 | 0000000 TPad12 000000000000 |
| 0000000000000000000000 | 000000000000000000000000000 |
BLANK BLANK BLANK BLANK …
BLANK BLANK BLANK BLANK | 00 TPad21 000 | 000 TPad22 00 |
BLANK BLANK BLANK BLANK …

{
   TCanvas *c = new TCanvas("c", "c", 800,800);
   c->Draw();
   TPad *p1 = new TPad("p1","p1",0.1,0.2,0.9,1.);
   p1->Draw();
   p1->Divide(2,1);
   TPad *p11 = (TPad*)p1->cd(1);
   p11->SetFillColor(kRed);
   p11->Draw();
   TPad *p12 = (TPad*)p1->cd(2);
   p12->SetFillColor(kRed-1);
   p12->Draw();

   c->cd(0);
   TPad *p2 = new TPad("p1","p1",0.1,0.,0.9,0.2);
   p2->Draw();
   p2->Divide(2,1);
   TPad *p21 = (TPad*)p2->cd(1);
   p21->SetFillColor(kBlue);
   p21->Draw();
   TPad *p22 = (TPad*)p2->cd(2);
   p22->SetFillColor(kBlue-1);
   p22->Draw();
}

Hi, thanks for the solution.
I was missing the command
c->cd(0);
However in this set up, if I put p1->Divide(2,1); => p1->Divide(2,1,0,0); the TPad is split with no space in between (i.e. no space between columns). However I see that there is a gap in between Row1 and Row2. Is there a solution to this so that no blank space is there in between?

Okay got it, I think p1->SetTopMargin(0.0) will work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.