TransWikia.com

Image with border and fill

TeX - LaTeX Asked by Iván Vega on June 13, 2021

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}{dimexprtextwidth-2fboxsep-2fboxrule}
            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

2 Answers

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}

Answered by Zarko on June 13, 2021

Why not simply a parbox in a fcolorbox ?

mwe

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

Answered by Fran on June 13, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP