0

With the following example:

\documentclass[]{article}

\usepackage{tikz,wrapfig,lipsum}

\begin{document}

\begin{wrapfigure}{r}{4cm}
  \includegraphics[width=4cm]{fondo}
  \caption{This figure looks ok, i.e. placed in the center with respect to the
    caption}
\end{wrapfigure} 
\lipsum[1-2]
 
\begin{wrapfigure}{r}{4cm}
  \begin{tikzpicture}
  \path(0,0) node(A){\includegraphics[width=4cm]{fondo}};
  \end{tikzpicture}
  \caption{This picture seems to be shift right, i.e. not in the center with respect
    to the caption.}
\end{wrapfigure} 
\lipsum[1-2]
  
\end{document} 

I get this:

First page showing the offset

How can I fix the small offset to the right of the second figure?

1 Answer 1

1

enter image description here

\documentclass[]{article}
\usepackage[demo]{graphicx} % remove the demo option in actual document.
\usepackage{tikz,wrapfig,lipsum}

%%% for the red border around the text. Do not use in actual document.
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}

\begin{wrapfigure}{r}{4cm}
  \includegraphics[width=4cm]{fondo}
  \caption{This figure looks ok, i.e. placed in the center with respect to the
    caption}
\end{wrapfigure} 
\lipsum[1-2]
 
\begin{wrapfigure}{r}{4cm}
  \begin{tikzpicture}[every node/.style={inner sep=0,outer sep=0}] % <--------- added
  \path(0,0) node(A){\includegraphics[width=4cm]{fondo}};
  \end{tikzpicture}
  \caption{This picture seems to be shift right, i.e. not in the center with respect
    to the caption.}
\end{wrapfigure} 
\lipsum[1-2]
  
\end{document} 

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .