tl;dr How do I align text to text within \included graphics?

Let's look at the following logo, which I want to include (in a vector format, e.g. pdf or svg). enter image description here

The blue/red lines are my annotations.

While the logo is a vector image, it is an external image. How do I let LaTeX know where the 'baseline' is? Or where, in this image, to left-align text to? See red/blue lines respectively.

Most of my LaTeX documents are rather hack-ish at the moment, I am trying to find an elegant solution for this.

Things I've considered:

  • Meddle with the bounding box. What are the drawbacks?
  • Manually position the logo. To avoid resizing issues, I'd have to find (e.g. baseline) as relative height.
  • I have little knowledge of PDF as a language, but is there a way to tell LaTeX, e.g. "go use the bottom left corner of element ", since I am including vector graphics?
  • Maybe I can include the graphic with tikz, and then manually position the anchor?

I would appreciate any suggestions you guys might have.

  • Since the external image is self-contained, there is no reference to whether it includes text or "just graphics" - they're all the same. Also, by default, the baseline is set as the bottom of the image. Sure you can manipulate that, but the default is to have no depth, putting the bottom of the image on the baseline.
    – Werner
    Aug 29 '13 at 19:19
  • @Werner, if I were to convert the vector drawing to pgf code, would I then be able to do so? It would still be 'just graphics', but maybe I could reference pgf nodes?
    – kadrach
    Aug 29 '13 at 19:28
  • Maybe (I'm not familiar with SVG to PGF conversion in Inkscape, say). You may end up with separate nodes (or something) for each element in the original SVG which, again, has to technical reference to text or graphics. I guess it depends heavily on the source.
    – Werner
    Aug 29 '13 at 19:31

I'm not sure what tools are out there for changing the bounding boxes of images, but it can be done in LaTeX, as shown here. The primary tools I used are:

1) the \addvbuffer command of the verbatimbox package for vertically padding a box with positive or negative padding; and

2) the \stackengine command from the package of the same name. When the 7th parameter (known as \useanchorwidth) is set true, the total stack takes the horizontal width of the stack's anchor object.

I just made sure that the anchors were rules of the desired sizes. There are four parameters to set, shown near the top of the MWE.




\def\wwf{\addvbuffer[\topclip\ \bottomclip]{%

\parindent 0in
Left margin\vspace{1in}\par 
Here is the baseline
\bottominset{\color{red}\Huge \textsc{My Text}}{\wwfraw}{6cm}{1.5cm}

Here are the bounds of the raw image, as downloaded. The red boxes signify the (inclusive) extent of the lower left and upper right of the image

enter image description here

After processing, here is the image extent, again shown with red boxes:

enter image description here

Once you know the extent of the image, you can plan your text accordingly.

Of course, unless you feel compelled to set an origin to the image, you can place your text anywhere even on the raw image. For example, the last few lines of the MWE:

\bottominset{\color{red}\Huge \textsc{My Text}}{\wwfraw}{6cm}{1.5cm}

will produce the following, without any need to do the bounding-box alteration.

enter image description here

Of course, if you choose to operate on the processed image, then setting the inset text with a (0,0) offset from the lower left:

\bottominset{\color{red}\Huge \textsc{My Text}}{\wwf}{}{}

will place the lower left of the text on the blue/red registration marks.


Although in theory if you have the image in a vector format it may be possible to calculate the baseline, other issues usually mean you have to manually tweak it anyway, so unless you have to do thousands of such images, just adjusting the position by eye is usually sufficient. Really you don't need any additional packages for that, just \raisebox and \kern (or \hspace).

enter image description here





\kern-42pt WWF

  • Comparing our two answers, it is worth noting that \raisebox and \addvbuffer are not the same. With \raisebox, LaTeX knows that the negative part of the image still extends below the baseline. Thus, unless I'm mistaken, sticking it in a bottom-aligned float, for example, won't push the new baseline against the page base. Am I mistaken? As far as horizontal clip, of course the kern is easier...stupid me. Aug 29 '13 at 20:32
  • @StevenB.Segletes normally (out of the figure box) latex lines the baseline against the page botton unless the depth is too big (\maxdepth) in which case it moves it up, you can of course \smash the depth but then by default it overprints following text, so it all depends what's needed.... Aug 29 '13 at 20:37
  • With the kern, you fixed the right margin of the figure. However, because you can't kern to the left of the left margin, you can't use \kern to move the vertical blue registration line to the left margin, best as I can tell. Aug 29 '13 at 20:55
  • @StevenB.Segletes just put a -ve kern before the image include. Aug 29 '13 at 20:58
  • Ooo, that's new to me. Thanks for the pointer. Aug 29 '13 at 21:05

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.