I'm trying to insert an image with a rectangular border, and that rectangular border has a gray color, something like this: enter image description here

This is my code:

            \textcolor{Gris}{\caption{\sffamily{\textbf{The caption text}}}}

And the result I get is this:

enter image description here

As you can see, the gray fill is spilling over the edge, and that's what I want to avoid. Keep in mind that I am very new to Latex

  • Any news? You receive two answer, are none of them meet your expectations? If one do, be so kind and accept it (by clicking on check mark at top left side of this answer). With this you will inform audience here, the your problem is solved. Also with this you will earn 2 points of reputation :-)
    – Zarko
    Jan 29, 2021 at 9:09

2 Answers 2


Why not simply a \parbox in a \fcolorbox ?



Like this?

enter image description here

With use of the tikz package and example-image-duck instead of original image, which is not available to us:

figframe/.style = {
    draw=orange, very thick, fill= gray!30,
    minimum width=\linewidth, inner sep=2mm,
    text width= \pgfkeysvalueof{/pgf/minimum width} - 
            2*\pgfkeysvalueof{/pgf/inner xsep},
\usepackage[font={small, bf, sf}]{caption}

\tikz{\node [figframe]{
        \caption{The caption text}

You must log in to answer this question.

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