How to crop an eps file?

When you create a figure (in e.g. eps format) with R, the margins around the main context are always too wide. To save the space in the final documents, e.g. LaTeX generated pdf file. I have figured out two ways of reducing the margins.If you just want to shrink the white margin of an eps file, try Method A–C
If you want to crop an esp file, see Method D 

  • Method A (R users) Before you make your graph in R, use par(mar=c(bottom, left, top, right))to specify the margin you want to keep. The default value is c(5, 4, 4, 2) + 0.1. Try this example to see the differences.
    par(mar=c(5,4,4,2)+0.1) # The defualt margins plot(rnorm(100)) dev.copy2eps()          # Save as eps 
    par(mar=c(4,4,0,0)+0.1) # Figure with very tight margins plot(rnorm(100)) dev.copy2eps()
  • Method B (use epstool) Very handy tool that can handle the optimal bounding box
    epstool --copy --bbox file.eps file_new.eps
  • Method C (use ps2epsi)It automatically calculates the bounding box required for all encapsulated PostScript files, so most of the time it does a pretty good job
    ps2epsi <input.eps> <output.eps>
  • Method D (DIY for any eps )Use a text editor open your eps file and you will find a line like this
    %%BoundingBox: 0 0 503 503

    in the front lines of the file. Adjust these vales to proper integers. Save it and test if the margins are better. When you want to crop an eps file and include it into LaTeX with \includegraphics command, you should use  \includegraphics* instead. Because If * is present, then the graphic is ‘clipped’ to the size specified. If * is omitted, then any part of the graphic that is outside the specified ‘bounding box’ will over-print the surrounding text. By the way, the options trim, bb, viewport options in \includegraphics can do the same job in a different manner without editing the eps file, see the help document for details.


Comments

6 responses to “How to crop an eps file?”

  1. Maelyson Santos Avatar
    Maelyson Santos

    Thanks!

  2. Meenakshi Avatar
    Meenakshi

    Thank you, method D worked for me

  3. Vittorio Avatar
    Vittorio

    Thanks a lot!

  4. James Avatar
    James

    Method A is perfect for R

  5. okan Avatar
    okan

    Thank you method B worked like a charm.

  6. Lei Wang Avatar
    Lei Wang

    Thanks. So cool. By the way, how do you get the url with your name? Is it supported by wrodpress?

Leave a Reply

Your email address will not be published. Required fields are marked *