The following code
annotation('textbox','String',{'\fontsize{10}TEST', '\fontsize{15}7,987,157', '\fontsize{10}+8,829'},'FontName','Consolas')
creates this box
One can notice that the third string is farther than the first one from the the middle one.
Moreover, by increasing the fontsize of the middle string, the last one will go even far away. Also the first string will go a little far away.
annotation('textbox','String',{'\fontsize{10}TEST', '\fontsize{25}7,987,157', '\fontsize{10}+8,829'},'FontName','Consolas')
Is there a way to reduce the line height or, similarly, to reduce the distance between the strings?

8 件のコメント

darova
darova 2020 年 4 月 28 日
Look ok on my computer (2013v)
Did you try another font?
giannit
giannit 2020 年 4 月 29 日
I tried with default font, arial, verdana, times new roman, but in all cases the strings are far away
darova
darova 2020 年 4 月 29 日
Here is the last idea i have
opengl software
giannit
giannit 2020 年 4 月 29 日
Output doesn't change :c thanks anyway for help
Ameer Hamza
Ameer Hamza 2020 年 4 月 29 日
giannit, can you tell what MATLAB release are you using and on which operating system. I tried it on macOS with R2020a, and I get the same output as you. But if I run this on the MATLAB online, it doesn't have extra space (image shown below). MATLAB online use Linux VM. I don't have access to a window machine to cannot try there.
giannit
giannit 2020 年 4 月 29 日
on windows 10.
I just tried on matlab online, the simple 1 line command of the question works without adding extra space, but when I add more sofisticated stuff, other things start to not work properly. I think this is due to limitation of matlab online
Ameer Hamza
Ameer Hamza 2020 年 4 月 29 日
I guess these functions were never intended for sophisticated text formatting with multi-line text. That is why there are some issues if the command becomes complex.
Adam Danz
Adam Danz 2020 年 4 月 29 日
編集済み: Adam Danz 2020 年 4 月 29 日
The problem is reproduced in r2020a using Windows 7. It appears that the space between lines n and n+1 is based on the fontsize that is in line n.
Note that the default verticalAlignment of the annotation is "top" but that only affects the entire text box as a whole, not each component within the textbox.

サインインしてコメントする。

 採用された回答

giannit
giannit 2020 年 5 月 1 日

4 投票

A workaround is simply to move the fontsize command of the last string to the middle string, that is
annotation('textbox','String',{'\fontsize{10}TEST', '\fontsize{25}7,987,157\fontsize{10}', '+8,829'},'FontName','Consolas')

3 件のコメント

darova
darova 2020 年 5 月 1 日
Adam Danz
Adam Danz 2020 年 5 月 1 日
Well done
Ameer Hamza
Ameer Hamza 2020 年 5 月 1 日
So simple, yet so tricky.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

質問済み:

2020 年 4 月 28 日

コメント済み:

2020 年 5 月 1 日

Community Treasure Hunt

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

Start Hunting!

Translated by