1

I am trying to export figures from MATLAB in publication quality for importing into LaTeX documents.

I am able to set all the graphics properties I would like, however when I export my figure as a .eps, the box around the legend disappears.

MWE below (I'm using MATLAB 2014b):

figure
plot(1:4)
legend('A line!')
print('LineTest','-depsc2','-tiff')

In LaTeX:

\usepackage{graphicx}
\usepackage{epstopdf} %converting to PDF

\begin{document}

    \includegraphics[width=\textwidth]{LineTest}

\end{document}

This gives the following result, which has no legend box: enter image description here

Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
B. Thomas
  • 192
  • 9

2 Answers2

1

It works fine for me with using Matlab 2016a and your TeX document. The following TeX document also works, try it, maybe it is an issue with your TeX compiler:

\documentclass[a4paper]{article}
\usepackage[pdftex]{graphicx}

\begin{document}

    \includegraphics[width=\textwidth]{LineTest.eps}

\end{document}

Running epstopdf manually on the EPS image also gives a PDF with the legend in a box. Can you run it from the command line and see whether the problem is still there for you?


FYI my version of pdflatex:

pdfTeX 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian)
kpathsea version 6.2.1
Copyright 2015 Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Peter Breitenlohner (eTeX)/Han The Thanh (pdfTeX).
Compiled with libpng 1.6.17; using libpng 1.6.17
Compiled with zlib 1.2.8; using zlib 1.2.8
Compiled with poppler version 0.41.0
Jonathan H
  • 7,591
  • 5
  • 47
  • 80
  • Hm, when I run eps2pdf from command line gives the same result, with no box around the legend. Running your tex document returns the following error for me: Unknown graphics extension: .eps. \includegraphics[width=\textwidth]{ALineTest.eps} I would normally need the following in my preamble: \usepackage{epstopdf} – B. Thomas Sep 12 '16 at 12:28
  • @B.Thomas That might be an issue with your pdflatex version then, what OS are you on and how did you install LaTeX? – Jonathan H Sep 12 '16 at 12:29
  • I'm on Windows 10 (64bit) and I installed LaTeX a fair while ago. I'm currently using TexStudio to write in, which is using Miktex 2.9. I'm not sure how to get my pdftex version though? – B. Thomas Sep 12 '16 at 12:33
  • @B.Thomas Very sorry but I'm not familiar with Windows/Miktex, hopefully another SOuser might be able to help you with that. – Jonathan H Sep 12 '16 at 13:06
0

I had a similar issue. I was saving two figures as eps files and using them in Latex. The figures were saved automatically using:

print(filename, '-depsc2', '-tiff')

I was using TexStudio and Miktex 2.9 with the command:

\includegraphics[width=\textwidth]{filename.eps}

The first file did not have the bounding box around the legend but the second file did.

The work around I found was to manually save the figure (Figure → Save As...) as filename.eps. The bounding box then showed up in TexStudio.

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
TD57
  • 1