Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question

migrated from stackoverflow.com Aug 5 '11 at 22:25

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

    
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

2 Answers 2

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}

Boxed figures

share|improve this answer

Try with:

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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.