Variable Title - Mutiple Lines

Platform: Linux / C++
Compiler: Clang

I want label my y-axis with multiple lines.
For example
first line = velocity
second line = m/s
I use

   mg->GetYaxis ()->SetTitle (

Which works. But I want to use variable names and units.
So if I call the function again, I might want to use e.g. {acceleration}{m/s^2}

How can I use variable input for the #splitline command?

Form() is the answer.

mg->GetYaxis ()->SetTitle (Form("#splitline{%s}{m/s}",variable_name));
1 Like

BTW, it seems you have an extra “}” after velocity

Thanks it works.
One more kind of related question.

If I use the #splitline{}{} those two lines will not be centered, but left-aligned (“linksbündig”)
Is there a way to center-align them.

I already use

      mg->GetYaxis ()->CenterTitle ();

but that will only center the overall #splitline{}{}, not each line.
I_want.pdf (15.4 KB)
I_have.pdf (15.4 KB)

No, there’s no control on that. Sorry.

You can just add spaces to approximate the centering, e.g.

  mg->GetYaxis()->SetTitle(Form("#splitline{%s}{   m/s}","velocity"));

(3 spaces in this case)
It needs some trial and error and won’t be perfect, but close enough :slight_smile:

1 Like