I am almost done with my thesis and I include a lot of Matlab generated .eps files. I noticed that on some of those the image in the resulting document is cut off on the right hand side just enough to look bad.

When I searched the forums I saw some people had seemingly similar problems in the past but their solutions (don't use a vector format for a photographic image, use the epstopdf package to include the eps file) did not work for me or did not apply to my case.

The eps file is fine when viewed but the resulting "-eps-converted-to.pdf" file is cut off. I would like to include a minimal working example but I don't know where to put the eps file?

For my document I am using Texmaker with the "fast compile" setting: PdfLaTeX + Bib(la)tex + PdfLaTeX (x2) + View Pdf. For the MWE I just pressed PdfLaTeX a few times before viewing.

What I would like as a solution: Have epstopdf not cut off my eps files!

What I would not like to do: Convert every eps file by hand or re-plot/re-export all my images from Matlab!

I hope you can help me get this resolved! Thanks a lot! :)

EDIT: Marjin pointed out that changing the BoundingBox in the eps file (in a text editor) could solve the problem, and it did! This solution falls into the 'edit all eps files by hand' category, so any idea to automate the process would be much appreciated!





  • 1
    An EPS file contains plain text and you can open them in a text editor. To help in answering the question you can post the first 20 lines or so of an example EPS file. Importantly, the start of the file contains information on the Bounding Box which is most likely responsible for the cut-off. Especially when all or most of your images are the same size this should be easy to fix automatically (and if they are different sizes then it can still be done but with a little bit more scripting).
    – Marijn
    Aug 2, 2021 at 15:59
  • @Marijn Thank you for your input. When I opened one of the offending eps files in a text editor and manually changed the value %%BoundingBox: 3 0 338 252 to %%BoundingBox: 3 0 340 252 it was not cut off by epstopdf anymore! Do you have an idea how to resolve the problem for a large number of eps files?
    – becky
    Aug 2, 2021 at 16:12
  • The easy situation is if all of your files have currently a bounding box of (3,0)-(338,252) and you want to change all of them to (3,0)-(340,252). Then you can run a search and replace in the terminal, which is one line of code that changes all the files in one run. If you use Linux or Mac this is very easy, if you use Windows then it is a bit harder because you might need to install some utilities. However, if your images are of different sizes, or if the cut-off is not always 2px, then you need to write a small script (e.g., in Perl or Python) to find the current values, add the 2px,
    – Marijn
    Aug 2, 2021 at 16:21
  • and write the new values to all the files.
    – Marijn
    Aug 2, 2021 at 16:21
  • I vaguely remember a similar issue: matlab sometimes calculates a wrong bounding box. However I cannot remember if it popped out here or on some other SE site...
    – campa
    Aug 2, 2021 at 16:21

1 Answer 1


With the information from the comments, I now have the following solution:

The Matlab generated eps files should all have the same size (width and height) but they all have slightly different boundary boxes when opened in a text editor, for example:

%%BoundingBox:     3     0   338   252

I changed that line for all files to:

%%BoundingBox:     0     0   340   255

The pdf file generated by epstopdf does not have any cut off parts now. Now I just need to find out how to make Matlab generate the correct boundary boxes...

Thank you all for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.