TLegend *legend = new TLegend(0.6, 0.7, 0.9, 0.9); legend->AddEntry(graph, "Data", "l"); legend->SetTextAlign(kTextLeft); legend->Draw();
TLegend *legend = new TLegend(0.1, 0.1, 0.5, 0.3); legend->AddEntry(h1, "Histogram 1", "f"); legend->AddEntry(h2, "Histogram 2", "f"); legend->SetTextAlign(kTextCenter); legend->Draw();This code creates a legend box with a horizontal position of 0.1 and a vertical position of 0.1, and a width of 0.4 and a height of 0.2. The legend entries for two histograms named "Histogram 1" and "Histogram 2" are added with the option "f", which specifies a filled area plot. Finally, the SetTextAlign method is called with the kTextCenter constant, which aligns the text to the center of the legend box. Package library: ROOT framework.