Centering axis title with use of TF1?

What would be the command to put in my .rootstyle.C file in order to have all my graphs automatically updated with an axis (X & Y) title in the middle of the axis?

The following doesn’t work for me:


In the style sheet: MatthieuStyle->SetTextAlign(22);

Or directly in the code:
TCanvas *c5 = new TCanvas(“c5”,"",0,0,800,600);
c5->cd();
TLegend leg2= new TLegend(0.6,0.1,0.8,0.4);
TF1
neut_plot_recEne1 = new TF1(“neut_plot_recEne1”,neutralino_rate,1.0,200,3);

neut_plot_recEne1->SetParameter(0,10);
neut_plot_recEne1->SetParameter(1,xsec);
neut_plot_recEne1->SetParameter(2,244);
neut_plot_recEne1->SetLineColor(kBlack);
neut_plot_recEne1->SetLineStyle(9);
neut_plot_recEne1->Draw();

neut_plot_recEne1->GetXaxis()->SetTitle(“Fluorine Recoil Threshold Energy (keV)”);
neut_plot_recEne1->GetYaxis()->SetTitle(“Event Rate (kg^{-1}d^{-1})”);
neut_plot_recEne1->GetXaxis()->CenterTitle(true);
neut_plot_recEne1->GetYaxis()->CenterTitle(true);

det71RecEnedata->Draw(“pSAME”);
det72RecEnedata->Draw(“pSAME”);

leg2->AddEntry(neut_plot_recEne1,“10GeV”,“l”);
leg2->AddEntry(neut_plot_recEne2,“30GeV”,“l”);
leg2->AddEntry(neut_plot_recEne3,“100GeV”,“l”);
leg2->AddEntry(det71RecEnedata,“Det 71 Data”,“p”);
leg2->AddEntry(det72RecEnedata,“Det 72 Data”,“p”);

gPad->SetLogx(1);
c5->Modified();
c5->Update();
c5->SaveAs(“fig_Count_Rate_71_72_WIMP_Response_recEne.png”);

I’ve spent all day looking for this but to no avail.

Thanks

To center the Y (and X) axis tithe on a given histogram (hpx) do:

hpx->GetYaxis()->CenterTitle(true);

There is no global setting for that.

It’s all good, I found a solution…

The reason why the code below
(
neut_plot_recEne1->GetXaxis()->CenterTitle(true);
neut_plot_recEne1->GetYaxis()->CenterTitle(true);
)

didn’t work is because I added “gPad->SetLogx(1);” after “CenterTitle(true)”.

If you put “gPad->SetLogx(1);” before “CenterTitle(true)” everything works fine!