MATLAB Answers

Matlab label with different colors on the string using latex interpreter

129 views (last 30 days)
Oyeniyi
Oyeniyi on 14 Apr 2016
Commented: Chibuzo Nnonyelu on 18 Dec 2018
How do I specify different font colors on the same string using the TEXT, TITLE, XLABEL, YLABEL, or ZLABEL commands etc., while using the LATEX interpreter. For example, the command below works well with the TEX interpreter, how do I get it (or something similar) to work with the LATEX interpreter.
\color{red}x \color{green}+ \color{blue}y

  0 Comments

Sign in to comment.

Accepted Answer

Daniel Lyddy
Daniel Lyddy on 18 Sep 2017
Suppose you have a 3-vector called 'titleColor' that holds the RGB components of the color you want to assign to the title (which I will call 'titleString').
tStr = sprintf('\\color[rgb]{%f, %f, %f}%s', titleColor, titleString);
title(tStr);
I haven't tried this trick with labels yet, but I don't see why a similar approach would not work.
And yes, there are two backslashes before the color[rgb] in the code above. The sprintf command drops one of them.

  2 Comments

Sungwoo Park
Sungwoo Park on 19 Mar 2018
Does this really work? Mine just showed '\color[rgb]{0.500000, 0.500000, 0.500000}Title'

Sign in to comment.

More Answers (0)

Sign in to answer this question.