LaTeX in multi-line MATLAB headers

I need to create a two-line headline on a MATLAB chart using LaTeX in each of the lines.

title({'first line','second line'}) 

works, but not with LaTeX. In one line of the name MATLAB, LaTeX is understood as in the example:

 title(['$y=x^2$'],'interpreter','latex') 

I tried many things, but I was not able to get MATLAB to create a multi-line header with LaTeX in these lines.

+5
source share
3 answers

Prior to version R2017a, using an array of cells, as suggested by other answers, force left alignment. This is apparently fixed in R2017b.

You can wrap the title in a LaTeX table environment:

 figure; plot((1:5).^2); title('\begin{tabular}{c} first_line \\ second_line \end{tabular}', ... 'interpreter', 'latex') 

This will allow you to choose the alignment of the text. Replace {c} either {r} or {l} for text aligned left and right, respectively.

+3
source

If you run

 title({'$y=x^2$','$y=x^2$'},'interpreter','latex') 

You will get a two-line header with the correct LaTeX setting.

+5
source

You can use sprintf to create a line for the title , explicitly with a newline, '\n' .

 title(sprintf('$y=x^3$\n$sin(x)$'), 'interpreter', 'latex'); 
+1
source

Source: https://habr.com/ru/post/1235356/


All Articles