1

Although I have rendered my legend text with LaTeX in MATLAB as follows

set(myLegend, 'fontsize', 8, 'interpreter','latex', 'Position', [0.67, 0.12, 0.3, 0.01]);

I still feel that the texts are rather different from my main texts. For example, the texts seem so ugly, because the letters are too far apart. Plus, the strikes are so thin.

enter image description here

How can I make them look exactly the same as the caption below?

Sibbs Gambling
  • 19,274
  • 42
  • 103
  • 174
  • I don't have a direct answer as I had the same problem. The only solution I can suggest is to go to **tex** rather than **latex** as it works great and is almost the same for most purposes – The-Duck Mar 18 '14 at 21:54
  • @The-Duck Do you mean replace latex with tex in that command? – Sibbs Gambling Mar 18 '14 at 21:55
  • exactly: `'interpreter,'tex'` and I am sure you can figure most of it yourself as LaTex is just the improved Tex and Delta t is still `\Deltat` – The-Duck Mar 18 '14 at 22:03
  • @The-Duck I tried, but $\Delta t$ no longer works. – Sibbs Gambling Mar 18 '14 at 22:06
  • 2
    Remove the dollar chars ($) and try again – The-Duck Mar 18 '14 at 22:49
  • It can have various reasons, check all possible solutions in this answer: [Greek letters in axes labels are not working](http://stackoverflow.com/questions/21103033/greek-letters-in-axes-labels-are-not-working) I hope it helps. – Robert Seifert Mar 18 '14 at 23:04

2 Answers2

0

You can actually export your Matlab figure by using Matlab2tikz. Once you get your Matlab figure, just insert it in your LaTeX file by \input{myfigure.tex}.

Using Matlab2tikz is really easy, as stated in the README file:

The workflow is as follows.

  1. a. Place the matlab2tikz scripts (contents of src/ folder) in a directory where MATLAB can find it (the current directory, for example).

    b. Make sure that your LaTeX installation includes the packages

    • TikZ (aka PGF, >=2.00) and
    • Pgfplots (>=1.3).
  2. Generate your plot in MATLAB.

  3. Invoke matlab2tikz by Matlab matlab2tikz(); or matlab2tikz('myfile.tex'); The script accepts numerous options; check them out by invoking the help, help matlab2tikz Sometimes, MATLAB makes it hard to create matching LaTeX plots by keeping invisible objects around or stretches the plots too far beyond the bounding box. Use Matlab cleanfigure;matlab2tikz('myfile.tex');` to first clean the figure of unwanted entities, and then convert it to TeX.

  4. Add the contents of myfile.tex into your LaTeX source code; a convenient way of doing so is to use \input{/path/to/myfile.tex}. Also make sure that at the header of your document the Pgfplots package is included

This should be in your .tex file:

\documentclass{article}
\usepackage{pgfplots}
% and optionally (as of Pgfplots 1.3):
\pgfplotsset{compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
\newlength\figureheight
\newlength\figurewidth
\begin{document}
\input{myfile.tex}
\end{document}
Mario S. E.
  • 129
  • 1
  • 8
0

This is how I normally embed latex in legends,

l = legend('$\alpha$', '$\dot{\alpha}$', '$x$', '$\dot{x}$'); set(l, 'interpreter', 'latex', 'location', 'northwest', 'FontSize', 15)

For some reason, possibly a bug, it only works when when you set the interpreter via the object's setter.

To do the above caption try,

l = legend('(b) $t=9:00 \Delta t$ set(l, 'interpreter', 'latex')