I'm using standalone to produce, well, standalone formulae. However, sometimes they end up being cropped too close and parts get left off. I'm including a sample .tex file and output. What can I do to ensure that standalone makes the image as small as possible, but no smaller?

$2^5 = x_5 * y^8$

The border around the image is not present in the PDF, it's from my screen capture. I left it to show that the text bleeds over the edge.

  • 1
    Hi mrjf, welcome to TeX.sx! I included the image for you, soon you'll have enough reputation for that yourself. Also, we don't usually put a greeting or a "thank you" in our posts, so I removed that. While this might seem strange at first, it is not a sign of lack of politeness, but rather part of our trying to keep everything very concise. Have fun on the site!
    – Jake
    Apr 25, 2012 at 6:06
  • 4
    Explanation: To assure that the characters are "visually" aligned, especially those characters which "protude" slightly from the usual rectangular bounding box (like the "spikes" of the 5 or the arch of the "8"), the characters actually exceed their own bounding box, which can't be measured by the standalone package. btw, I'm getting a sufficient border by default, but maybe I have a different package version. Apr 25, 2012 at 6:13
  • Thank you Jake, I appreciate the image help and style pointers. Thanks for the explanation Stephan, I figured it was the subs-and-supers that were hard to measure.
    – mrjf
    Apr 25, 2012 at 6:19
  • 1
    Note that its class=article not article, but this class is the default anyway. Apr 25, 2012 at 6:25
  • 1
    @StephanLehmke: Yes, the default border setting changed from v0.x to v1.0. It's a pain, I know, but I wanted to have suitable default values for the main use case of standalone. The default can be changed back in the global or a local standalone.cfg file. Apr 25, 2012 at 6:30

4 Answers 4


You can use the border=<len> class option to increase the width of the border around the cropped output:

enter image description here



$2^5 = x_5 \times y^8$


As in your case, the border around the image is not present in the PDF, it's from my screen capture.

It is also possible to modify this border for left/right and top/bottom border using border={<l/r> <t/b>} or for each border specifically using border={<l> <b> <r> <t>}. These options are described in the standalone documentation (section 5.2 Class options).

Incorporating Stephan Lehmke's comment, this is what the bounding boxes around the objects in the equations look like:

enter image description here



\setlength{\fboxsep}{-\fboxrule}% Remove \fbox separation for tight bounding box


$\bbox{2^5} = \bbox{x_5} \times \bbox{y^8}$


By setting \fboxsep to -\fboxrule, the outer edge of the boxes represent the bounding boxes exactly. It is now noticeable that some elements protrude outside this, causing the problems when clipping.

  • Ahh that is doing the trick nicely. Thanks so much Werner, I really appreciate it. I had searched the docs for margin and padding, but not border. I guess I tend to think of a border as being visible. Very happy to have this working, thanks!
    – mrjf
    Apr 25, 2012 at 6:18
  • 1
    @mrjf: You need to have the border because standalone crops to the official size of the content, which is sometimes smaller than the characters. E.g. italic characters fall out to the right slightly so they can overlap with following characters etc. You can't detect that on the class level. Note that v1.0 of standalone changed the border to 0 and uses the crop option, while v0.x used the preview option which had a border of 0.50001bp by default. Apr 25, 2012 at 6:27
  • 4
    @MartinScharrer: Maybe you could include padding or margin as synonyms for the border option? I had the same problem a while back, because I too think of a border as something thin and visible.
    – Jake
    Apr 25, 2012 at 6:33
  • @MartinScharrer I would make a slight border the default. I guess there are less people who want an "absolutely tight" clipping than vice versa. Apr 25, 2012 at 6:36
  • @Jake: I can do that. I originally used the same name as preview does. Apr 25, 2012 at 6:50

Maybe this is not an answer to your question. In addition to be honest, I do not understand the philosophy of existence of standalone when pdfcrop exits. This is what I would do instead:

Create test.tex as follow:

  $2^5 = x_5 * y^8$

run pdflatex test.tex so that test.pdf is produced.

run pdfcrop test.pdf test-cropped.pdf

  • 2
    You've highlighted a (the?) reason in your answer: standalone does this in one step, while you have to perform this in two. In comparison, while making a stop-over en route to your destination still gets you there, some people would rather take the direct flight and avoid any overlays.
    – Werner
    Apr 25, 2012 at 14:06
  • It is easy to do it in one step. Just use write18 and few lines of TeX coding!
    – Simurgh12
    Apr 25, 2012 at 14:43
  • Interesting, thanks Simburgh12. I'll keep that option in mind. My use case is embedding LaTeX in Markdown files to be processed into HTML (via ImageMagick conversion of PDFs).
    – mrjf
    Apr 29, 2012 at 8:35
  • Although, I would have preferred standalone to do the job, I have also found that it is sometimes easier to just use pdfcrop.
    – stiaan
    Sep 16, 2016 at 9:59
  • I find this method is better. I was getting strange cropped results using "standalone".
    – CJ7
    Nov 18, 2021 at 4:48

TeX itself doesn't know anything about the actual extent of the visible characters/glyphs. It only uses rough box metrics (height, depth, width, italic correction, etc.) stored in TFM files to align the text. Since the glyphs may exceed their corresponding box -- as you can see in this example, it's usually impossible to compute a perfect bounding box using TeX/LaTeX. That's why you have to adapt it manually or approximate it.

Nonetheless, some DVI drivers like dvisvgm offer an option to analyze the glyphs and derive a tight box for the resulting image.


2019 reporting in. I can't comment on the accepted answer due to lack of Rep on this particular sub SE.

The order is actuallyborder={<l> <b> <r> <t>}, not LRBT. An edit from a user with edit privilege would be appreciated.

  • Thank you very much for given correction in @werner answer. I took a liberty to edit it and ad information taken from recent version (3.1a) of package/manual.
    – Zarko
    Nov 1, 2019 at 18:33

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.