How do I turn off the LaTeX interpreter per line in my title within MATLAB?
21 次查看(过去 30 天)
显示 更早的评论
Hi all,
I'm looking to have, within a title, two lines: the top one a LaTeX formated text (including subscript and a \Delta symbol), and the lower line with some text that I want to disable the formatting as it would look messy - e.g. my sample name is '14_6_520', but at the moment this would subscript the 6 and 5, as shown in the image below:

I understand that to put two lines in a plot title, it requires the following code after plot:
title({'First line';'Second line'})
The top title (this is the one I want with the formatting)
Plotting = '\Delta{H_{Irr-Uir}} vs Disp'
The lower title (this is the one I don't want to have formatted - here I would enter 14_6_520):
ID = string(inputdlg('Enter the name to ID this data with:')); %this is where, in the GUI, I'd enter the text 14_6_520
Putting these together in to a plot title with two lines would look like this:
title({(Plotting);(ID)});
but I'd like 'ID' with 'interpreter' set to 'none' to tell it I don't want the lower line to be formatted, which I thought would be achieved with this code:
title({(Plotting);(ID,'Interpreter','none')});
However this does not work. Is there a way to choose interpreter on/off (by line) within the title? Many thanks!
0 个评论
回答(1 个)
Star Strider
2025-7-17
编辑:Star Strider
2025-7-17
Probably the easiest way to do what you want would be to 'escape' the underscore lines using backslashes (\) --
figure
title(["$\Delta{H_{Irr-Uir}} vs Disp$" "$14_66_20$"], Interpreter='LaTeX') % Original
figure
title(["$\Delta{H_{Irr-Uir}} vs Disp$" "$14\_66\_20$"], Interpreter='LaTeX') % Underscores 'Escaped'
EDIT --
If the lines are entered with the underscores, use the strrep function to add the backslashes automatically --
numstr = '14_66_20'
numstresc = strrep(numstr, '_','\_')
.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Control and Callbacks 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

