[Tex/LaTex] Standalone: document size

marginsstandalone

For me the "standalone" documents is useful to produce a document with a size that matches exactly the document. However, here is an example where the final size is to small:

enter image description here

Here is the same document, with an aditional 'A':

enter image description here

Do you know why the size of the first arrow is not the good one, and how to correct that?

Thank you!

MWE:

\documentclass{standalone}
\begin{document}$\leftarrow$\end{document}

Best Answer

As the TeX Book says (p. 63)

From TeX's viewpoint, a single character from a font is a box [...] The character shape need not fit inside the boundaries of its box.

Here we have such a situation: the \leftarrow is larger than the box, as the following snippet shows

\documentclass{article}

\begin{document}

\setbox0=\hbox{$\leftarrow$}
\rule{\wd0}{\ht0}\box0
\quad
\setlength{\fboxsep}{-\fboxrule}
\fbox{$\leftarrow$}

\end{document}

enter image description here

However, standalone doesn't know that, so we must force it to consider a somewhat larger box. One easy way is to insert some vertical phantom, like \vphantom{A} or even a simple \strut. Alternatively, the standalone class accepts an optional argument border with syntax

border=〈length (all sides)〉
border={〈length (left/right)〉 〈length (bottom/top)〉}
border={〈length (left)〉 〈length (right)〉 〈length (bottom)〉 〈length (top)〉}

So in this case one might use

\documentclass[border=2pt]{standalone}

or

\documentclass[border={0pt 0pt 0pt 2pt}]{standalone}

if you want the border only above.

Related Question