20

I am having trouble perfectly getting an image to embed within a line of text. Ideally, the image is to be scaled to the correct size so that it fits within the line of text. This is as far as I've gotten. While it is close, the image is too tall. Any ideas? Thanks!

\documentclass[preprint2]{aastex}

\usepackage{graphicx}

\newcommand*{\img}[1]{%
    \raisebox{-.02\baselineskip}{%
        \includegraphics[
        height=\baselineskip,
        width=\baselineskip,
        keepaspectratio,
        ]{#1}%
    }%
}

\begin{document}

\begin{enumerate}
\item When ready, click `record \img{Record.png}'.  There will be a three second period before the actual data collection begins.
\end{enumerate}

\end{document}

Here's an image if what I get with this:

Sample image

2
  • A complete example would be appreciated.
    – cfr
    Commented Aug 2, 2015 at 3:07
  • 1
    You could manually set a image size in your \img definition. Use height=0.8\baselineskip and width=0.8\baselineskip. Commented Aug 2, 2015 at 3:29

2 Answers 2

25

Like this?

tiger integrated

\documentclass{article}
\usepackage{graphicx,calc}
\newlength\myheight
\newlength\mydepth
\settototalheight\myheight{Xygp}
\settodepth\mydepth{Xygp}
\setlength\fboxsep{0pt}
\begin{document}
  This is some arbitrary \raisebox{-\mydepth}{\fbox{\includegraphics[height=\myheight]{tiger}}} line of uninteresting text.
\end{document}

As written, this will not adapt to font size changes within the document. You can, however, define a new \inlinegraphics{} command which does so:

\documentclass{article}
\usepackage{graphicx,calc}
\newlength\myheight
\newlength\mydepth
\settototalheight\myheight{Xygp}
\settodepth\mydepth{Xygp}
\setlength\fboxsep{0pt}
\newcommand*\inlinegraphics[1]{%
  \settototalheight\myheight{Xygp}%
  \settodepth\mydepth{Xygp}%
  \raisebox{-\mydepth}{\includegraphics[height=\myheight]{#1}}%
}
\begin{document}
  This is some arbitrary \raisebox{-\mydepth}{\fbox{\includegraphics[height=\myheight]{tiger}}} line of uninteresting text.

  This should adapt \inlinegraphics{example-image-a}.

  \Huge Will this adapt \inlinegraphics{example-image-b} nicely?

  \tiny That is yet to be \inlinegraphics{example-image-a} seen.
\end{document}

adaptive tigers

2
  • That seems to be exactly what I am looking for, thank you very much! I apologize if the question was not asked well, I didn't quite know how to ask it.
    – Spahn711
    Commented Aug 2, 2015 at 3:17
  • 3
    @Spahn711 You're welcome. The question seemed fine but with fragments of code it is always something of a guessing game. A complete small document makes the question clearer. I wasn't quite sure, for example, if you needed something which will adapt to local context. See edit if you do. EDIT: I hope it works in your class!
    – cfr
    Commented Aug 2, 2015 at 3:19
10

Simply lower from 0.3\baselineskip:

\documentclass{article}%[preprint2]{aastex}

\usepackage{graphicx}

\newcommand*{\img}[1]{%
    \raisebox{-.3\baselineskip}{%
        \includegraphics[
        height=\baselineskip,
        width=\baselineskip,
        keepaspectratio,
        ]{#1}%
    }%
}

\begin{document}

\begin{enumerate}
\item When ready, click `record \img{Vinyl.png}'. There will be a three second period before the actual data collection begins.
\end{enumerate}

\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 .