[Tex/LaTex] How to avoid large margins around Matlab plot in PDF

cropgraphicsMATLABpdf

I am preparing image files to be included in a latex document. The image file is generated by printing a Matlab plot.

If I print the plot in eps format, the content of the eps file is fully occupied with the plot;

if I print the plot in pdf format, then there are big margins above and below the plot in the pdf file;

if I use ps2pdf to convert the eps file into a pdf file, the big margins will be added above the plot.

I would like to use pdflatex, so I prefer pdf format of image files. I was wondering how I can save the plot in pdf format without the big margin above and below the plot?

Best Answer

This is partially off-topic, since LaTeX doesn't have anything to do with how the PDF is generated. Nonetheless, it's relevant enough for my tastes.

In Matlab, you can create a cropped PDF by setting the papersize to the same size as the graphic; see this small figuresize.m function to do this automatically.

Usually if you're generating graphics from Matlab, though, I'd recommend using matlabfrag so that your figure labels are typeset by LaTeX. You can use psfrag-based graphics in pdfLaTeX by using the pstool package.

Finally, if you just want to crop a graphic, TeX Live and MiKTeX both come with a command line tool pdfcrop to perform this on an arbitrary PDF.