[Tex/LaTex] Create a wrapfigure with side caption and place it in the upper right corner

graphicspositioningsidecapwrapfigure

I want to use the wrapfig packet to wrap text around an image. Since the image is longer than wide I'd like the caption to be aside of the image. Finally, the image should be placed in the upper right corner of my document. Currently it looks like this:

enter image description here

I tried to place the caption on the right side of the image. Therefore I tried to use the sidecap package and the SCfigure environment. Here is an example code (with an example image) that demonstrates my attempt:

\documentclass{article}    
\usepackage{mwe}% for this example only
\usepackage{wrapfig}
\usepackage{sidecap}


\begin{document}

\begin{wrapfigure}{r}{1.8cm}
    \begin{SCfigure}
      \begin{center}
        \includegraphics[width=1.5cm]{example-image}
      \end{center}
      \caption{Example side caption text for example image}
  \end{SCfigure}
\end{wrapfigure}

\lipsum[2]

\end{document}

Unfortunately this won't work. The image doesn't get printed. Hence I have two questions:

  1. How can one combine wrapfig and sidecap?
  2. How can one place a wrapfigure in the upper right corner?

Edit: "how can one place a wrapfigure"

The wrapfigure is defined between two paragraphs. I do not know where the page break occurs. So I am looking for a solution that ensures that the wrapfigure will always be in the upper right corner, something like: \begin{table}[t].

Cras nec ante. Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel,
wisi. 

\begin{wrapfigure}{r}{1.8cm}
      \begin{center}
        \includegraphics[width=1.5cm]{example-image}
      \end{center}
      \caption{Example side caption text for example image}
\end{wrapfigure}

Morbi auctor lorem non justo. Nam lacus libero, pretium at,
lobortis vitae, ultricies et, tellus. Donec aliquet, tortor sed accumsan bibendum,
erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et
nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante.

Best Answer

You don't need sidecap!. What you need is two minipages:

\documentclass{article}    
\usepackage{mwe} %% for this example only
\usepackage{wrapfig}
% \usepackage{sidecap}


\begin{document}

\begin{wrapfigure}{r}{4.5cm}
    \begin{minipage}{2cm}
    %\begin{SCfigure}
      \centering
        \includegraphics[width=1.5cm]{example-image}
    \end{minipage}%
    \begin{minipage}{2cm}
      \caption{Example side caption text for example image}
%  \end{SCfigure}
    \end{minipage}
\end{wrapfigure}

\lipsum[2]

\end{document}

enter image description here

You can adjust the bad boxes by adjusting the width of second minipage in your actual file.

You have to place the wrapfigure code snippet at appropriate place in your code so that it appears at upper right corner and try not to float it.

Related Question