3

.Hello tex.se community,
I have a problem when I put a\frame around an overpic environment. The top border of the frame is overlapped by the picture.

Is it a bug or a wrong use of\frame command ? I can't find anithing on the Internet or tex.se.

I just want to put a frame around the image.

Here is the mwe :

\documentclass{article}
\usepackage{graphicx}
\usepackage{overpic}

\begin{document}
\begin{figure}
    \centering
    \frame{\includegraphics[width=0.7\textwidth]{foo}}
    \caption{framed figure include with \emph{includegraphics}.}
\end{figure}
\begin{figure}
    \centering
    \frame{\begin{overpic}[width=0.7\textwidth]{foo}
        \put(50,20){foo}
    \end{overpic}}
    \caption{framed figure include with \emph{overpic}.}
\end{figure}
\end{document}

Edit 1

The issue doesn't seems to come from the viewer and thin border rendering. See this screenshot of the pdf rendering with xpdf and evince. In this case, the image is a grey square an cross the right border of the frame. screenshot

EDIT by cfr

The following image can be used to reproduce the issue:

img.png

Adapted MWE:

\documentclass{article}
\usepackage{graphicx}
\usepackage{overpic}

\begin{document}
  \begin{figure}
    \centering
    \frame{\includegraphics[width=0.7\textwidth]{img}}
    \caption{framed figure include with \emph{includegraphics}.}
  \end{figure}
  \begin{figure}
    \centering
    \frame{\begin{overpic}[width=0.7\textwidth]{img}
        \put(50,10){foo}
      \end{overpic}}
    \caption{framed figure include with \emph{overpic}.}
  \end{figure}
\end{document}

Effect:

too small frame

  • do you need the frame to be so tight? \fbox is the normal command and includes some padding. – David Carlisle Mar 8 '15 at 21:06
  • Welcome to TeX SE! What exactly is the problem? The two cases look pretty much the same when I compile - except for the additional text in the second case. (I replaced your image by another, of course, as I don't have foo.) – cfr Mar 8 '15 at 21:07
  • @DavidCarlisle I want the frame to stick to the image borders, it work with includegraphics but not with overpic. the same issue arise with fbox. – fwachtel Mar 8 '15 at 21:12
  • @cfr the second image with overpic mask the top border of the frame. – fwachtel Mar 8 '15 at 21:13
  • My guess is that the image box generated by overpic is too small in height. – fwachtel Mar 8 '15 at 21:15
2

It's an artefact of your viewer, but you can avoid the problem.

I see

enter image description here

and as you see, both lose some edges, but zooming in shows

enter image description here

with all edges showing.

However you can make the pdf less delicate by drawing the frame after the image so it is on top:

Page 2 shows as follows at all zoom levels:

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage{overpic}

\begin{document}
\begin{figure}
    \centering
    \frame{\includegraphics[width=0.5\textwidth]{house}}
    \caption{framed figure include with \emph{includegraphics}.}
\end{figure}
\begin{figure}
    \centering
    \frame{\begin{overpic}[width=0.5\textwidth]{house}
        \put(50,20){foo}
    \end{overpic}}
    \caption{framed figure include with \emph{overpic}.}
\end{figure}

\clearpage


\begin{figure}
    \centering
    \sbox0{\includegraphics[width=0.5\textwidth]{house}}%
    \usebox{0}%
    \kern-\wd0\frame{\phantom{\usebox0}}
    \caption{framed figure include with \emph{includegraphics}.}
\end{figure}
\begin{figure}
    \centering
    \sbox0{\begin{overpic}[width=0.5\textwidth]{house}
        \put(50,20){foo}
    \end{overpic}}%
    \usebox{0}%
    \kern-\wd0\frame{\phantom{\usebox0}}
    \caption{framed figure include with \emph{overpic}.}
\end{figure}

\end{document}
  • I'm afraid it's not a rendering issue (see question Edit 1). you can try the pdf here tempsend.com/031D28982F Also my images are not white/transparent on border so your second solution isn't suitable :/ – fwachtel Mar 8 '15 at 22:23
  • See my edit above. It is easier to reproduce with a coloured semi-transparent image. – cfr Mar 8 '15 at 22:53
2

Partial Solution

[using overpic package v0.53 2010/09/13]

Possible explanation

The overpic package makes operations on the dimensions of the image to fit with the local basis used to position overlapping object. It seems that there is some approximations in these operations that lead to a wrong dimension of the image in the local basis. As the image is placed relatively to the bottom-left corner, it goes over the picture box on right or top side.

Solution

It appear that the approximation of the image dimensions is different when the package is loaded with option percent, permil or abs.
In my case, the permil option seems to not introduce any error, with a correct framed image.

comparison

Bug fix ?

I looked the overpic.sty file but I'm not expert in TeX at all.
If somebody can confirm my thought, we could fix this.
It's only a hundred of line file.

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.