Right align text in subtitle

12 views (last 30 days)
John Cruce
John Cruce on 12 Sep 2021
Commented: Chunru on 30 Oct 2021
I've created a multi-line title and I need a second string of text right aligned on the second line:
t = title({['\fontsize{14}','First line'];['\fontsize{10}',sprintf('Second line left aligned %s',stringarray),'Second line right aligned']},'FontWeight','Normal');
I'm striking out on how to do this. Should I create another line of text and try to find the position of the title then right align? Or is there a way to do this within a multi-line title?
  2 Comments
Chunru
Chunru on 30 Oct 2021
Thanks for introducing the subtitle() function, which may be helpful in many other applications. However, it won't help if we want to have part of string to be aligned left and other aligned right as OP asked.

Sign in to comment.

Accepted Answer

Chunru
Chunru on 12 Sep 2021
Edited: Chunru on 12 Sep 2021
figure;
plot(randn(10,1))
t = title({['\fontsize{14}','First line']; ...
' '}, ...
'FontWeight','Normal');
axPos = get(gca, 'Position');
xl =xlim;
%t.Position(1) = xl(2);
text(xl(1), t.Position(2), 'Second Line Left Aligned', ...
'HorizontalAlignment', 'left', 'VerticalAlignment', 'bottom');
text(xl(2), t.Position(2), 'Second Line Right Aligned', ...
'HorizontalAlignment', 'right', 'VerticalAlignment', 'bottom');
set(gca, 'Position',axPos);

More Answers (0)

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!