1

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:

\begin{figure}
\lineskip=-\fboxrule
\textcolor{Orange}{
    \colorbox{Gray}{
      \fbox{\begin{minipage}{\dimexpr\textwidth-2\fboxsep-2\fboxrule}
            \centering
            \includegraphics{imagenes/ejemplo_cubo_OLAP.png}
            \abovecaptionskip=0pt
            \textcolor{Gris}{\caption{\sffamily{\textbf{The caption text}}}}
            \end{minipage}
        }
    }
}
\end{figure}

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

1
  • 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

3

Why not simply a \parbox in a \fcolorbox ?

mwe

\documentclass{article}
\usepackage{graphicx,xcolor,lipsum}
\begin{document}
\lipsum[1][1-3]
\begin{figure}[h]\fboxrule3pt\fboxsep2em
\fcolorbox{orange}{lightgray}{%
\parbox{\dimexpr\linewidth-2\fboxsep-2\fboxrule}{\centering%
\includegraphics[width=.8\linewidth]{example-image}%
\caption{\lipsum[2][1-2]}}}
\end{figure}
\lipsum[1][4-8]
\end{document}
2

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:

\documentclass{article}
\usepackage{tikz}
\tikzset{
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},
    align=center}
        } 
\usepackage{graphicx}
\usepackage[font={small, bf, sf}]{caption}

\begin{document}
\begin{figure}
\tikz{\node [figframe]{
        \includegraphics{example-image-duck}%{imagenes/ejemplo_cubo_OLAP.png}
        \caption{The caption text}
                      };
    }
\end{figure}
\end{document}

You must log in to answer this question.

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