Different colors for different text in a single textbox

33 Ansichten (letzte 30 Tage)
Mark Stone
Mark Stone am 24 Dez. 2022
Kommentiert: Walter Roberson am 28 Mai 2025
Is it possible to have different colors for different text in a single text box?
For example,
1st line of text is black
2nd line of text is blue
3rd line of text is red.

Akzeptierte Antwort

Voss
Voss am 24 Dez. 2022
str = { ...
'\color{black}1st line of text', ...
'\color{blue}2nd line of text', ...
'\color{red}3rd line of text'};
t = text(0.5,0.5,str);
  4 Kommentare
Keqin Xu
Keqin Xu am 28 Mai 2025
What if I want to use more colors that don't even have a name?
Walter Roberson
Walter Roberson am 28 Mai 2025
str = '\color[rgb]{0.1,0.8,0.95} Sample rgb text';
text(0.5,0.5,str)
Note that for this to work, the text() Interpreter property must be 'tex' (which is the default)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by