4

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:

enter image description here

Here's the icon (as a PNG) I'd like to use.

Related:

  • Could you post a full compilable code using this specific environment? – Bernard Nov 9 '18 at 22:27
  • I made the example image with Pages not TeX. I added the thumbnail image linked in the text above. – M.R. Nov 10 '18 at 1:39
  • What type of code input are you after? You talk about paragraphs and environments... just wondering since they aren't exactly the same. – Werner Nov 10 '18 at 1:51
2

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

enter image description here

LEFT MARGIN VERSION

enter image description here

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.