# Figures with borders problem

I am writing my thesis in TexniCenter and I have the following problem. I want all my figures to have a border. So I use :

\usepackage{float}
\floatstyle{boxed}
\restylefloat{figure}


in the beginning.

However, every figure after that has a border with width equal to text width, even it is much smaller. For example I use the following code to include an image:

\begin{figure}[h]
\centering
\includegraphics [width=0.5\textwidth] {myfigure.png}
\caption[myfigure]%
{myfigure}
\label{myfigure}
\end{figure}


I want to have a figure with width half the text width. The border though remains full width size. Could you help me please.

-
The following question might be of help: How to add border for an image? –  Alan Munn Aug 5 '11 at 22:38
You mention that every figure after \restylefloat{figure} has a border of width equal to text width. Do you want every figure to have a border of width 0.5\textwidth instead? Or just some of your figures? –  Werner Aug 5 '11 at 23:16

## migrated from stackoverflow.comAug 5 '11 at 22:25

This question came from our site for professional and enthusiast programmers.

You may use the floatrow package and its \ffigbox command with the optional argument \FBwidth:

\documentclass{article}

\usepackage{floatrow}
\floatsetup[figure]{style=boxed}

\begin{document}

\begin{figure}
\ffigbox[\FBwidth]{%
\rule{5cm}{1cm}% placeholder for image
}{%
\caption{A figure}%
}
\end{figure}

\begin{figure}
\ffigbox[\FBwidth]{%
\rule{3cm}{1cm}% placeholder for image
}{%
\caption{A figure}%
}
\end{figure}

\begin{figure}
\rule{3cm}{1cm}% placeholder for image
\caption{A figure}
\end{figure}

\end{document}


-

Try with:

\begin{figure}
\centering
\begin{tabular}{|c|}
\hline
\rule{0.5\linewidth}{0pt}\vspace{-10pt}\\
\includegraphics{figure} \\
\hline
\end{tabular}
\end{figure}

-