Font size and font type

I'm writing a LaTeX document with \documentclass[pdftex,11pt,openright,headsepline]{book}.

I'm now creating plots in Matlab and I want to have the axis and title of these plots to have the same font size and font as the text.

What font size and font type do I have to choose?

• Is this a question about how to set font properties in Matlab? If so, it doesn't have anything to do with TeX. May 28, 2015 at 10:27

You need to make the interpreter of the text as 'latex':

xlabel('\textbf{Example $a^2$}','Interpreter','latex'); % for x axis's text
ylabel('\textbf{Example $b^2$}','Interpreter','latex'); % for y axis's text
title('Example','Interpreter','latex'); % for title's text
h=legend('show'); % for legend's text, assuming you have given the strings for legend already in the plot command
set(h,'Interpreter','latex');


to your code for plotting. This will make the interpreter for the text you write in the axes and the legend appear formatted with latex not tex (which is default). So, you get the latex type text on the axes too. You can write anything you want the way you write in latex (like $a^2$, etc.). If you further want to change the font in the latex interpreter, you can add:

\fontfamily{cmtt}\fontseries{b}\selectfont test


and you can change the font to cmtt family, for example.

Hope it helps!

Edit:

set(0,'DefaultTextInterpreter','latex');


and set the default interpreter for all strings in matlab as latex. Look here for more on defaults:

http://in.mathworks.com/help/matlab/creating_plots/default-property-values.html#f7-18841

Edit 2:

I just realized you wanted to change the font size too. Here, add something like this in the arguments:

xlabel('\textbf{Example $a^2$}','Interpreter','latex','fontsize',14); % I've set the size as 14 here, you can set whatever you want.


This way you can add this extra term to the arguments wherever you want to change the font's size.

• Thank you very much. I tried it and it seems to work. So when I have \documentclass[pdftex,11pt,openright,headsepline]{book} then I should use in Matlab "'fontsize',11" and "'Interpreter','latex'. Right? May 28, 2015 at 11:46
• Yes, sure. Exactly like you said.
– RS06
May 28, 2015 at 14:08
• Note: This works for text() as well in MATLAB 9.2.0.556344 (R2017a). Jan 16, 2019 at 0:14

You can also make MATLAB generate the .tex file for you, by using matlab2tikz, which is "a script to convert MATLAB/Octave into TikZ figures for easy and consistent inclusion into LaTeX" available on https://www.mathworks.com/matlabcentral/fileexchange/22022-matlab2tikz-matlab2tikz

This is very useful if you have to deal with many charts generated by MATLAB. By working with .tex files, the final products remains consistent if you, for any reason, change the fonts in your document or include your charts in another document. Drawback: if data change, you have to regenerate the MATLAB plot, then the .tex file, and finally compile the document again.

You don't have worry about the font size and style, as you can see in the following example, where the text font (Palatino) and size has been kept in the chart. Notice that you may still have to fix something or customize the code to obtain what you want. Also, the example I show you dates back to 2012, while the script available online has been updated recently.

% This file was created by matlab2tikz v0.2.1.
% Copyright (c) 2008--2012, Nico Schlömer <nico.schloemer@gmail.com>
%
%
%
\begin{tikzpicture}

\begin{axis}[%
every axis y label/.append style={rotate=-90},
axis lines=middle,
view={0}{90},
width=\figurewidth,
height=1.2\figureheight,
%scale only axis,
xmin=-0, xmax=1,
xlabel={$z_h / b_v$},
xmajorgrids,
y dir=reverse,
ymin=-0.9, ymax=-0.5,
ymajorgrids,
name=plot1,
ylabel={$C_{Y_{\beta_v}} \, (\si{\radian^{-1}})$},
%title={Sideforce derivative},
legend style={at={(0.03,0.90)},anchor=north west,nodes=right}]
color=black,
mark size=3.5pt,
mark=o
]
coordinates{
(0,-0.609244430498508)(0.1,-0.589569218432885)(0.2,-0.575580003823558)(0.3,-0.564720763857404)(0.4,-0.557085538078227)(0.5,-0.555584036143151)(0.6,-0.565871990115845)(0.7,-0.595749175477526)(0.8,-0.653467629096353)(0.9,-0.74440910676988)(1,-0.866688483793922)
};

color=black,
mark size=3.5pt,
mark=triangle
]
coordinates{
(0,-0.595312937013058)(0.1,-0.594216172156085)(0.2,-0.591285259055598)(0.3,-0.587582342745093)(0.4,-0.584824333687759)(0.5,-0.585302910887511)(0.6,-0.591772526244447)(0.7,-0.607280530796657)(0.8,-0.634798332622844)(0.9,-0.677639499267638)(1,-0.740595972655539)
};

color=black,
mark size=3.5pt,
only marks,
mark=square
]
coordinates{
(0,-0.639839932916833)
};

color=black,
mark size=3.5pt,
only marks,
mark=diamond,
]
coordinates{
(0,-0.795654227407493)
};

color=black,
mark size=3.5pt,
only marks,
mark=*
]
coordinates{
(0.82,-0.668926601130689)
};

color=black,
mark size=3.5pt,
only marks,
mark=triangle*
]
coordinates{
(0.82,-0.642004556024089)
};

\end{axis}

\begin{axis}[%
every axis y label/.append style={rotate=-90},
axis lines=middle,
view={0}{90},
width=\figurewidth,
height=\figureheight,
%scale only axis,
xmin=-0, xmax=1,
xlabel={$z_h / b_v$},
xmajorgrids,
ymin=0, ymax=30,
ylabel={$\% \, \Delta$},
ymajorgrids,
at=(plot1.below south west), anchor=above north west]
color=black,
solid,
forget plot
]
coordinates{
(-0.0101010101010101,2.00423589528513)(0.0101010101010102,1.98513676330423)(0.0303030303030303,1.37608243346336)(0.0505050505050506,0.758949234476695)(0.0707070707070707,0.133575348526556)(0.0909090909090908,0.500205392814883)(0.111111111111111,0.999235610868496)(0.131313131313131,1.3858185234428)(0.151515151515152,1.77615347435414)(0.171717171717172,2.17029535393037)(0.191919191919192,2.56830012843458)(0.212121212121212,2.88590197672501)(0.232323232323232,3.14968658370057)(0.252525252525253,3.4155021124051)(0.272727272727273,3.68337210808616)(0.292929292929293,3.95332048136197)(0.313131313131313,4.16910846939229)(0.333333333333333,4.35581230060881)(0.353535353535354,4.54354348811356)(0.373737373737374,4.73231053499549)(0.393939393939394,4.92212203843935)(0.414141414141414,5.03145178747091)(0.434343434343434,5.10606561382981)(0.454545454545455,5.18076081445205)(0.474747474747475,5.25553752253107)(0.494949494949495,5.33039587155124)(0.515151515151515,5.230317559302)(0.535353535353535,5.07294027455566)(0.555555555555556,4.91672845994868)(0.575757575757576,4.76166921676807)(0.595959595959596,4.60774983594119)(0.616161616161616,4.13145582830931)(0.636363636363636,3.58489228565705)(0.656565656565657,3.04965030370611)(0.676767676767677,2.52538171487842)(0.696969696969697,2.01175248282245)(0.717171717171717,1.04768027535438)(0.737373737373737,0.0395650146794334)(0.757575757575758,0.931172583550881)(0.777777777777778,1.86657344855685)(0.797979797979798,2.76853257808149)(0.818181818181818,4.09174740288066)(0.838383838383838,5.3941632552252)(0.858585858585859,6.62886598741652)(0.878787878787879,7.80100245416585)(0.898989898989899,8.9152107849498)(0.919191919191919,10.1780395648388)(0.939393939393939,11.3728913566219)(0.95959595959596,12.4955127915158)(0.97979797979798,13.5522613404144)(1,14.5487696555531)
};

% Annotazione differenza percentuale dei piani montati in fusoliera
\node[coordinate,pin=-60:{$\Delta_\textup{body mounted} = 24\%$}]at (axis cs:0,24.3521) {};

\end{axis}
\end{tikzpicture}