9

I have the following code to show a picture around by some textes.

\documentclass{article}
\usepackage{wrapfig}
\usepackage{lipsum}

\begin{document}

\begin{wrapfigure}{r}{4cm}
  \begin{center}
    \includegraphics[width=0.2\textwidth]{mickey}
  \end{center}
\end{wrapfigure}

\lipsum[1-4]

\end{document}

The problem is that I want to put the photo on (exact) top right of the page. So I want to remove the blank marge above the photo and on the right of the photo. Also I feel that the blank marge below the photo is too much.

Does anyone know how to amend the code?

enter image description here

SoftTimur
  • 19,767
  • 1
    Don't use the center environment. Instead, use \centering. – Werner Feb 25 '15 at 05:18
  • and what about controling the marge on the right hand side? I could control it by \begin{wrapfigure}{r}{4cm}, but is there a easy way to make sure that it is exactly right justified with the page? – SoftTimur Feb 25 '15 at 05:25
  • Do you want the right and top of the photo to align with the text border or the page border? –  Feb 25 '15 at 05:28
  • 1
    Use width=\linewidth. – Werner Feb 25 '15 at 05:28

1 Answers1

5
  1. Don't use the center environment. Use \centering instead.

  2. To adjust the horizontal spacing, you need to adjust the length \columnsep (see section 2 Sizing and optional overhang of the wrapfig documentation).

enter image description here

\documentclass{article}
\usepackage{wrapfig,graphicx,lipsum}

\begin{document}

\setlength{\columnsep}{1pt}%
\begin{wrapfigure}{r}{4cm}
  \centering
  \includegraphics[width=\linewidth]{example-image}
\end{wrapfigure}

\lipsum[1-4]

\end{document}

If the vertical spacing at the bottom doesn't suit your needs, then you could use the adjustbox package to visually trim the content, or reduce the image's height from TeX's point of view:

enter image description here

\documentclass{article}
\usepackage{wrapfig,lipsum,graphicx}

\begin{document}

\setlength{\columnsep}{1pt}%
\begin{wrapfigure}{r}{4cm}
  \centering
  \includegraphics[trim=0pt 12pt 0pt 0pt,width=\linewidth]{example-image}
\end{wrapfigure}

\lipsum[1-4]

\end{document}

Alternatively, specify the number of rows to re-align

% # of rows -------|
%                  v
\begin{wrapfigure}[8]{r}{4cm}
  \centering
  \includegraphics[width=\linewidth]{example-image}
\end{wrapfigure}
Werner
  • 603,163