Aligning or justifying multiple text on same title line

조회 수: 7 (최근 30일)
John Cruce
John Cruce 2017년 3월 26일
댓글: John Cruce 2017년 3월 26일
Hi all,
I'm looking for a little help on a seemingly simple problem. I have a multiline title similar to this on a plot:
t = title({['\fontsize{14}','First Line Title']; ...
['\fontsize{12}','Second Line Title 1', ...
'Second Line Title 2','Second Line Title 3']}, ...
'FontWeight','Normal')
On the second line I have three pieces of text (Second Line Title 1-3). I'm exporting multiple plots, but the text changes for each plot I make. I'm wanting the alignment (justification) of each piece of text on the second line to remain constant regardless of number of characters so that there isn't a big swing in the justification of each piece of text. Hopefully this makes sense.
Does anyone have any suggestions on how to do this in MATLAB? Any thoughts or advice would be greatly appreciated!
  댓글 수: 2
Jan
Jan 2017년 3월 26일
The question is not clear: Currently the 2nd line is the big string:
'Second Line Title 1Second Line Title 2Second Line Title 3'
What should exactly appear where and what is a "big swing"?
John Cruce
John Cruce 2017년 3월 26일
I want the second line of the title on each of the two plots to look like this:
Abcde Fghij Klmno
Abcdef Ghijklm Nopq
Not this:
Abcde Fghij Klmno
Abcdef Ghijklm Nopq
So that the three text pieces are each justified on that single line. Does that make sense?

댓글을 달려면 로그인하십시오.

답변 (1개)

the cyclist
the cyclist 2017년 3월 26일
편집: the cyclist 2017년 3월 26일
I don't know how to easily do the justification off the top of my head.
Note that the text object t has some properties that look promising, such as 'HorizontalAlignment' and 'Position'. You could try manipulating those. I thought the first one would do it, but I could not easily get it to work with your multi-line title.
A rather unsatisfying solution would be to pad the right-hand side of your string with space characters, such that your total character count is always equal. Maybe if someone doesn't offer a better solution, you could do that.
  댓글 수: 1
John Cruce
John Cruce 2017년 3월 26일
I considered that as well. I also thought perhaps I could fudge a title line using annotation instead, then annotate each using essentially a text box to get the right position.
Thanks so much for the feedback.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by