[Tex/LaTex] Border around includegraphics

graphics

Seems like the problem of border around includegraphics has already been brought up. But none of the solutions worked for me.
Here's how my border looks like:
enter image description here
And here's the code:

\documentclass{article}
\usepackage{graphicx}
\usepackage[export]{adjustbox}
\usepackage{xcolor}
\begin{document}
lsdfjgofgkogkof kgdpgokfdgkdfog pdkpgodkgpodkg pfgkdgkdpgkf dgod k fpgkfdgdpfgod fkgdfgpdokfgop dkgpodkgop dkg dpgdkf gdkpdkog\\
\fbox{\includegraphics[center,cfbox=blue 1pt 1pt,fbox,frame]{name.png}}\\
kfogkdfpogkdf kpfogkfdpogdkf opdfkgpofdkgpodf kpofdgkopfdkgpdfk gpdfokgodfpk gdfopkgpofdkgodpfk pdofgk dfpk dgpokfgdfopgkdpf kpofg podfkgd pfokpfdgkpodfg
\end{document}

I'd be even more grateful if you could add in the comment how to better center the image as well. The above is the closest I could get to centered image.

Best Answer

Just try this:

\fbox{\includegraphics[width=\textwidth,center,cfbox=blue 1pt 1pt,fbox,frame]{name.png}}

Put "width" as first option in your includegraphics.

Another idea is to change margins just for the image using package changepage, like this:

In preamble put:

\usepackage{changepage}

An then use it adjusting relative to previous margin:

\begin{adjustwidth}{-1cm}{-1cm}
\fbox{\includegraphics[center,cfbox=blue 1pt 1pt,fbox,frame]{name.png}}
\end{adjustwidth}

Sustitute -1cm for the decrement of margin size you need.

Related Question