4

I'd like to include an inline image (to typeset hieroglyphic inscriptions) but I don't want it to stretch the line height, even if the image is too tall to fit. I don't mind it colliding with the line above and below and overlapping text, but the line height should be preserved at all costs.

Here is an example of incorrect line spacing:

enter image description here

The code used to produce this is

\raisebox{-0.75em}{\includegraphics[height=2em]{lorem_chickens.eps}} 

Now, this example is grossly exaggerated to demonstrate the issue. In actual usage, I would increase the line spacing and perhaps reduce the size of the image. However, if I could make the spacing work (no matter how ugly it looks) even on an extreme example like this, I could also make it work with reasonable line spacing and image size.

If I were doing this in HTML/CSS I would set a huge negative top margin on the image (<img href="lorem_chickens.svg" style="margin-top: -1000px" />) and the image would be overlapping with the text (which is, in my case, desired behaviour). But I don't know how to do this in LaTeX. Thanks for any help!

3
  • 3
    If you enclose the code in \smash{...}, the height and depth will be suppressed. Nov 13, 2019 at 13:12
  • Yes, that's exactly it. Please post it so I can mark it as answered. Thank you!
    – Kresimir
    Nov 13, 2019 at 13:14
  • Welcome to TeX.SE! Please post a minimal working example with your question that demonstrates your problem. Otherwise, I see it's already solved; so be sure to accept the answer! Nov 13, 2019 at 13:23

1 Answer 1

6

The command \smash{...} suppresses the height and depth of its argument, which will, in the OP's case, allow oversized images to be inserted without breaking the default line spacing.

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{graphicx}
\begin{document}
\lipsum[1]
\smash{\includegraphics[height=15pt]{example-image}}
\lipsum[2]
\end{document}

enter image description here

A different approach is to force the image by way of scaling, to fit in the allowed space. Here, \scalerel* indicates to scale the image to the vertical footprint of \strut (the default allotted line space).

\documentclass{article}
\usepackage[nopar]{lipsum}
\usepackage{graphicx,scalerel}
\begin{document}
\lipsum[1]
\scalerel*{\includegraphics{example-image}}{\strut}
\lipsum[2]
\end{document}

enter image description here

You must log in to answer this question.

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