Proper alignment of text bin labels

Hi,

I have a simple question. If I use text for the Xaxis bin labels, I get them not properly aligned, depending on which letters I use. You can see what I mean in the simple example below, where one can compare, for example, “pow” with “flower” :slight_smile:

const UInt_t nchannels = 5;

TString channelLabel[nchannels] =
  {
    "pow",
    "flower",
    "pet",
    "car",
    "bottle"
  };


void testBinLabel()
{
  TGraphErrors* ge = new TGraphErrors(nchannels);

  ge->SetMarkerSize (1.4);
  ge->SetMarkerStyle(kFullCircle);

  for (UInt_t i=0; i<nchannels; i++) {
    ge->SetPoint     (i,   i, 1.5*(i + 3));
    ge->SetPointError(i, 0.5, 0.1*(i + 2));
 } 


  TCanvas* canvas = new TCanvas();
  
  ge->Draw("ap");
  ge->GetYaxis()->SetTitle("");
  ge->SetTitle("");


  TAxis* xaxis = ge->GetXaxis();

  xaxis->SetLabelOffset(0.01);
  xaxis->SetLabelSize  (0.07);

  for (UInt_t i=0; i<nchannels; i++)
    xaxis->SetBinLabel(xaxis->FindBin(i), channelLabel[i].Data());

  xaxis->CenterLabels();
  xaxis->LabelsOption("h");
}

How can I fix it?

Thanks,
Jonatan

A brutal fix …

TString channelLabel[nchannels] =
  {
    "[pow]",
    "[flower]",
    "[pet]",
    "[car]",
    "[bottle]"
  };

Thank you Pepe Le Pew, but I hope there is a “non brutal” fix for this (apparently) simple problem of text alignment.

Another brutal fix …

TString channelLabel[nchannels] =
  {
    "POW",
    "FLOWER",
    "PET",
    "CAR",
    "BOTTLE"
  };

Well, you can also simply pretend it’s ART …

TString channelLabel[nchannels] =
  {
    "#scale[1.0]{#font[12]{#color[2]{p}}}#scale[0.7]{#font[22]{#color[3]{o}}}#scale[1.3]{#font[32]{#color[4]{w}}}",
    "#scale[1.0]{#font[42]{#color[5]{f}}}#scale[1.3]{#font[52]{#color[6]{l}}}#scale[0.7]{#font[62]{#color[7]{o}}}#scale[0.7]{#font[72]{#color[8]{w}}}#scale[1.3]{#font[82]{#color[9]{e}}}#scale[1.1]{#font[92]{#color[1]{r}}}",
    "#scale[1.0]{#font[102]{#color[30]{p}}}#scale[1.2]{#font[112]{#color[34]{e}}}#scale[1.3]{#font[12]{#color[38]{t}}}",
    "#scale[1.0]{#font[22]{#color[40]{c}}}#scale[0.7]{#font[32]{#color[41]{a}}}#scale[0.8]{#font[42]{#color[46]{r}}}",
    "#scale[1.0]{#font[52]{#color[20]{b}}}#scale[1.3]{#font[62]{#color[28]{o}}}#scale[1.2]{#font[72]{#color[29]{t}}}#scale[0.8]{#font[82]{#color[16]{t}}}#scale[1.1]{#font[92]{#color[5]{l}}}#scale[0.8]{#font[102]{#color[4]{e}}}"
  };

I like the last (colorful) version, but I doubt a journal would accept it… :slight_smile:

Well, they may accept one of these, though I personally find them rather boring …

TString channelLabel[nchannels] =
  {
    // Use "#color[0]" or "#color[19]" according to the value
    // returned by gPad->GetFillColor() or gStyle->GetCanvasColor()
    // so that the leading "|" character is NOT visible at all.
    // You may also use "{#int}" instead of "{|}".
    "#color[0]{|}pow",
    "#color[0]{|}flower",
    "#color[0]{|}pet",
    "#color[0]{|}car",
    "#color[0]{|}bottle"
  };
TString channelLabel[nchannels] =
  {
    // Use "#color[0]" or "#color[19]" according to the value
    // returned by gPad->GetFillColor() or gStyle->GetCanvasColor()
    // so that the leading "#bar{|}" character is NOT visible at all.
    // You may also use "{#int}" instead of "{|}".
    "#color[0]{#bar{|}}pow",
    "#color[0]{#bar{|}}flower",
    "#color[0]{#bar{|}}pet",
    "#color[0]{#bar{|}}car",
    "#color[0]{#bar{|}}bottle"
  };
TString channelLabel[nchannels] =
  {
    "#lower[0.1]{pow}",
    "#lower[-0.01]{flower}",
    "#lower[0.0]{pet}",
    "#lower[0.15]{car}",
    "#lower[-0.01]{bottle}"
  };

Thank you Pepe,

My final take is then

TString channelLabel[nchannels] =
  {
    "#color[0]{|}pow#color[0]{|}",
    "#color[0]{|}flower#color[0]{|}",
    "#color[0]{|}pet#color[0]{|}",
    "#color[0]{|}car#color[0]{|}",
    "#color[0]{|}bottle#color[0]{|}"
  };

Cheers,
Jonatan