# Embed small image within a line of text

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:

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

Like this?

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

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

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


• 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 Aug 2 '15 at 3:17
• @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 Aug 2 '15 at 3:19

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}