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.
To get a border for an image you can use the command \framebox{}
. To define the width of the rule you can use command \setlength{\fboxrule}{0.5pt}
.
Both combined leads to the following
\newcommand{\munepsfig}[4][scale=1.0]{% <===============================
\begin{figure}[!htbp]
\centering
\vspace{2mm}
\setlength{\fboxrule}{#4} % <===================================
\framebox{\includegraphics[#1]{#2.png}} % <=====================
\caption{#3}
\label{fig:#2}
\end{figure}
}
Now you can use the command
%\munepsfig[option]{figure}{caption}{fboxrule}
\munepsfig[width=5cm]{example-image}{caption of figure}{1pt}
to print the image example-image
with an border of 1pt
.
The complete MWE
\documentclass{article}
\usepackage{graphicx}
\newcommand{\munepsfig}[4][scale=1.0]{% <===============================
\begin{figure}[!htbp]
\centering
\vspace{2mm}
\setlength{\fboxrule}{#4} % <===================================
\framebox{\includegraphics[#1]{#2.png}} % <=====================
\caption{#3}
\label{fig:#2}
\end{figure}
}
\begin{document}
%\munepsfig[option]{figure}{caption}{fboxrule}
\munepsfig[width=5cm]{example-image}{caption of figure}{1pt}
\munepsfig[width=5cm]{example-image-a}{caption of figure2}{0.5pt}
\end{document}
gives you:
To get rid of the space between image and rule use command \setlength{\fboxsep}{0pt}
. See the following new MWE
\documentclass{article}
\usepackage{graphicx}
\newcommand{\munepsfig}[4][scale=1.0]{% <===============================
\begin{figure}[!htbp]
\centering
\vspace{2mm}
\setlength{\fboxrule}{#4} % <===================================
\setlength{\fboxsep}{0pt} % <===================================
\framebox{\includegraphics[#1]{#2.png}} % <=====================
\caption{#3}
\label{fig:#2}
\end{figure}
}
\begin{document}
%\munepsfig[option]{figure}{caption}{fboxrule}
\munepsfig[width=5cm]{example-image}{caption of figure}{1pt}
\munepsfig[width=5cm]{example-image-a}{caption of figure2}{0.5pt}
\end{document}
resulting in the pdf:
Best Answer
You can add a frame around it by placing it inside a
\fbox{...}
command.The distance can be set by changing the
\fboxsep
length and the line width with the\fboxrule
length, e.g. to draw a tight 1pt thick rule around the image use:Using a recent version of my
adjustbox
package you can use:There is also
cframe
andcfbox
for colored frames. All of these allow for multiple optional values, e.g.frame=<rule width>
. See the manual for more information.