sprintf in 2 lines, with 2 variables, in bold, and interpreter latex
23 次查看(过去 30 天)
显示 更早的评论
In the following example,
plot(1:10,1:10)
alpha = 3;
string = 'Hello';
text(5,5,sprintf('$\\textbf{%s}$ {\\boldmath$\\alpha=%d$}',string,alpha),'interpreter','latex','FontSize',20)
how can I bring the text corresponding to
'{\\boldmath$\\alpha=%d$}',alpha
to a second line, i.e. below the text "Hello"?
3 个评论
Dyuman Joshi
2024-4-23
编辑:Dyuman Joshi
2024-4-23
"how can I bring the text corresponding to a second line, i.e. below the text "Hello"?"
"is there a way to reduce the space between the two lines of text?"
The space in between the lines is proportional to the font-size.
If you can't change the fontsize for any particular reason, you will have to adjust the space manually by calling text() twice.
采纳的回答
Lokesh
2024-4-23
编辑:Lokesh
2024-4-23
Hi Sim,
It is my understanding that you would like to bring the text corresponding to "'{\\boldmath$\\alpha=%d$}',alpha" to a second line, i.e. below the text "Hello".
If the direct approach does not work as expected (and it seems to be the case here), I recommend using two separate text commands to place the content on two lines manually by adjusting the y-coordinates.
Below is a sample code snippet to place "alpha" on the second line:
plot(1:10,1:10)
alpha = 3;
string = 'Hello';
% First line of text
text(5,5,sprintf('$\\textbf{%s}$', string), 'interpreter', 'latex', 'FontSize', 20)
% Second line of text, adjust the y-coordinate for placement
text(5,4.5,sprintf('{\\boldmath$\\alpha=%d$}', alpha), 'interpreter', 'latex', 'FontSize', 20)
In this code, the second text command's y-coordinate is manually adjusted to 4.5 (from 5 to 4.5) to place it below the first line. You might need to adjust the 4.5 value depending on your desired spacing between the lines.
This approach ensures that the "alpha" value is displayed on a new line below your specified text by manually controlling their positions.
Hope this helps.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 LaTeX 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!