Varying Font Size Within individual words

조회 수: 16 (최근 30일)
Ben Korman
Ben Korman 2020년 4월 6일
댓글: Ben Korman 2020년 4월 9일
I need to produce the symbol "FA/FI" on the y-axis label with the "A" and the "I" in a font 3 sizes smaller than each "F". I do not want to use subscripts. In Microsoft Word, one achieves this by clicking on an icon on the toolbox. How does one do it in Matlab?
  댓글 수: 3
dpb
dpb 2020년 4월 9일
No problem...as noted, such a similar question so soon had me thinking along those lines already.
If solved the problem, why not "Accept" the Answer to indicate a solution found?
Wouldn't hurt to post the actual function/technique you found useful in the end as well.
Ben Korman
Ben Korman 2020년 4월 9일
The code I finally used is as follows. It allows the symbol in question to be added to a general description on the y-axis label:
fmt = '\\fontsize{%d} %s'; %format string for piece
fnLbl = @(FS,S) {[sprintf(fmt,FS,S(1)) sprintf(fmt,FS,S(2)) sprintf(FS-3,S(3)) sprintf(fmt,FS,'/') sprintf(fmt,FS,S(4)) sprintf(fmt,FS-3,S(5)) sprintf(fmt,FS,S(6))]};
lbl = fnLbl(12,'(FAFI)'); % Specifies fontsize and string to be processed
str = ['Fraction of Inspired Concentration', lbl];
newstr= join(str);
ylabel(newstr)
This produces a label on the y-axis consisting of a description "Fraction of Inspired Concentration" followed by a space, followed by the appropriate symbol.

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

채택된 답변

dpb
dpb 2020년 4월 6일
Amazing how the same or similar queries seem to come in bunches...
hAx=gca;
hAx.XTickLabel(3)={'\color{red}\fontsize{8}\bf 3'};
did one tick value for the OP there. Just string together the two pieces you need. Write a simple function to produce the desired string passed the text and sizes if doing it for more than just one or two specific cases.
fmt='\\fontsize{%d} %s'; % format string for piece
>> [sprintf(fmt,8,'F',5,'A') '/' sprintf(fmt,8,'F',5,'I')]
ans =
'\fontsize{8} F\fontsize{5} A/\fontsize{8} F\fontsize{5} I'
>>
or, more directly to use passed string, size--
fnLbl=@(FS,S) {[sprintf(fmt,FS,S(1)) sprintf(fmt,FS-3,S(2)) sprintf(fmt,FS,'/') sprintf(fmt,FS,S(3)) sprintf(fmt,FS-3,S(4))]};
>> lbl=fnLbl(8,'FAFI')
lbl =
1×1 cell array
{'\fontsize{8} F\fontsize{5} A\fontsize{8} /\fontsize{8} F\fontsize{5} I'}
>> hAx.XTickLabel(4)=lbl;
produced the desired string. More logic in a function could make it somewhat simpler.
But, MATLAB handle graphics aren't a word processor and there's no fancy GUI to mung on stuff inside the tick labels array. Guess one could write one.
NB: Above w/ default 'TeX' interpreter as per the link...

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by