5

Writing

\documentclass{standalone}
\usepackage{varwidth}

\begin{document}
\begin{varwidth}{\linewidth}
  {\em line 1}

  {\em line 2}
\end{varwidth}
\end{document}

produces an incorrect bounding box for italics (note that the '2' is clipped):

enter image description here

How can one generate a correct standaline image? Simply modifying \linewidth to a fixed dimension does not work.

(As discussed here, inserting varwidth is necessary to avoid that standalone would merge the two lines on one line.)

4
  • @percusse When I looked at my question just after posting it, the latex source (which I had indented by 4 spaces) looked right. Now I see that it is only after your edit that it looks right, and it was on one line before your changes. What have you done? Was I writing LFs rather than CRLFs, or some such issue?
    – Calaf
    Jun 16, 2013 at 17:14
  • another question addressing this problem: Standalone producing cropped / truncated formulae Jun 16, 2013 at 18:28
  • I've just clicked {} button on the menu. As you can seee from the edit the code was not indented when I did that.
    – percusse
    Jun 16, 2013 at 19:28
  • Hmm.. I had already done that. Doing so indents in the top (edit) window, which is interpreted as a request to format (and color) some code. Anyway.. all good then.
    – Calaf
    Jun 16, 2013 at 20:15

3 Answers 3

4

The problem that the character glyphs are outside their official font bounding boxes cannot be solved inside TeX, because TeX does only knows the official character bounding boxes and not their visual appearances.

Example:

\documentclass[varwidth]{standalone}

\begin{document}
  \raggedleft
  \itshape
  line f

  line $\not$
\end{document}

Clipped result

Part of f is not visible and \not has vanished entirely (extreme example, because \not has width zero, it overlaps the following relational operator).

As workaround a larger margin can be added:

\documentclass[margin=10pt,varwidth]{standalone}

And the result is cropped, e.g. via pdfcrop:

Result

3
  • I have already updated my answer for the previous question, before I saw this question. Therefore this answer repeats the latest part of the previous answer that better belong to this question. Jun 16, 2013 at 16:48
  • Using a margin is a suitable workaround, although the fact that it is not computed means that doing something like centering will be messed up. Since I am not doing this often, some fine-tuning by hand is not a bad idea. As an aside, each good answer generates even more questions. In this case: why are the "character glyphs outside their official font bounding boxes"?
    – Calaf
    Jun 16, 2013 at 17:04
  • @Calaf: In case of \not it is feature, then the characters in \not= are put on the same place, overlapping to get ≠. In other cases (f) it is the decision of the font designer. Jun 16, 2013 at 17:09
6

Compare the syntax along the lines of Will two-letter font style commands (\bf , \it , …) ever be resurrected in LaTeX?

\documentclass{standalone}
\usepackage{varwidth}

\begin{document}
\begin{varwidth}{\linewidth}
  \emph{line 1}

  \emph{line 2}
\end{varwidth}
\end{document}

enter image description here

3
  • I couldn't crop it properly for the screenshot sorry about that.
    – percusse
    Jun 16, 2013 at 16:42
  • Perhaps adding a border=1pt to the class options could be of help with the crop. Jun 16, 2013 at 16:46
  • @ClaudioFiandrino I normally use it but this time I tried to be honest about the actual bounding box :)
    – percusse
    Jun 16, 2013 at 22:15
3

Would \/ at the end be a good solution for you?

Change your MWE to

\documentclass{standalone}
\usepackage{varwidth}

\begin{document}
\begin{varwidth}{\linewidth}
  {\em line 1\/}

  {\em line 2\/}
\end{varwidth}
\end{document}  

Otherwise, use \textit instead of \em so to add automatically italic correction

\documentclass{standalone}
\usepackage{varwidth}

\begin{document}
\begin{varwidth}{\linewidth}
  \textit{line 1}

  \textit{line 2}
\end{varwidth}
\end{document} 
1
  • Simple and works fine for italics, but not general enough. It does not solve the case of using a font such as \newfont{\mypagko}{pagko scaled 3000}.
    – Calaf
    Jun 16, 2013 at 16:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .