I'd like a custom command or environment to add an image in the right margin at the top of a paragraph, which would look something like this:
Here's the icon (as a PNG) I'd like to use.
Related:
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI'd like a custom command or environment to add an image in the right margin at the top of a paragraph, which would look something like this:
Here's the icon (as a PNG) I'd like to use.
Related:
You didn't tell us anything about your environment, so I just picked one...quote
, and provide \margfig
.
\documentclass{article}
\usepackage{lipsum,graphicx,tabto,stackengine}
\newcommand\margfig[2][]{%
\leavevmode%
% \tabto*{-40pt}% LEFT MARGIN
\tabto*{\dimexpr\linewidth+40pt\relax}% RIGHT MARGIN
\smash{\belowbaseline[-\ht\strutbox]{\makebox[0pt]%
% [r]% LEFT MARGIN
[l]% RIGHT MARGIN
{\includegraphics[#1]{#2}}}}%
\tabto*{\TabPrevPos}%
}
\begin{document}
\lipsum[1]
\begin{quote}
\margfig[width=50pt]{example-image}
\lipsum[2]
\end{quote}
\lipsum[3]
\end{document}
RIGHT MARGIN VERSION
LEFT MARGIN VERSION