How to print path in figure title? It's screwing up my TeX markup
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Alexei
el 29 de Jul. de 2014
Comentada: Star Strider
el 29 de Jul. de 2014
What I want to achieve is a 3-line title over a plot which looks like this:
General Title
File name
Path where file lives
(The file name and path name refers to the file I used to do the calculations.) The different lines would have different properties -- for instance the General Title would have a larger font size than the two lines below it. Everything works as intended except for the path -- that screws up everything. If I exclude the path name, I can generate a nice 2-line title like this:
title({'\fontsize{16}Correlation Over Time';...
['\fontsize{9}\itFile\rm:',FileName]})
Note how I use TeX commands. It works as intended. As soon as I try to include the pathname, it all breaks. This is my attempt, just extending the logic of the above:
title({'\fontsize{16}Correlation Over Time';...
['\fontsize{9}\itFile\rm:',FileName];...
['\fontsize{9}\itPath\rm:',PathName]})
The TeX markup syntax and Windows path specification both use the '\' character, so matlab interprets the '\' characters in the PathName string as TeX commands. As a result, the entire title command breaks down, and it just spits out all the characters inside the parentheses unformatted. Is there any way for me to get around this?
Thanks!
0 comentarios
Respuesta aceptada
Star Strider
el 29 de Jul. de 2014
Editada: Star Strider
el 29 de Jul. de 2014
You have to replace the single backslant ‘\’ in the path name with double backslants ‘\\’ to make that work with TeX. They will print as single backslants though, so it will look as it should. The easiest way to do that is with the strrep function:
path = 'C:\Documents\MATLAB\DragonFiles';
PathName = strrep(path, '\', '\\');
You don’t have to change anything else, and it only changes the string you pass to your title call, leaving the actual path string unchanged. It worked when I tried it on a figure I created to test it, so you should have no problems with PathName created here.
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Annotations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!