0

I want to put figure caption in a box in main text so that having space between box and main text, and length of box must be equal the width of main text. I tried this code but it is not work

\documentclass{article}
\usepackage[demo]{graphicx}% demo option just for the example
\usepackage{framed}
\usepackage{caption}

\begin{document}
\captionsetup[figure]{labelfont={bf},labelformat={default},labelsep=period,name={Fig.}}

\begin{framed}
\begin{figure}
\begin{center}
  \captionsetup{labelfont={bf}}
  \caption{figure}{This is caption}
  \label{fig:1}
\end{center}
\end{figure}
\end{framed}

\end{document}

1 Answer 1

1

You can not use a figure environment inside a frame environment. So, put your frame inside your figure like it follows:

\documentclass{article}
\usepackage[demo]{graphicx}% demo option just for the example
\usepackage{framed}
\usepackage{caption}
    \captionsetup[figure]{labelfont={bf},labelformat={default},labelsep=period,name={Fig.},width=\textwidth}
\usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{figure}
    \begin{center}
        \begin{framed}
            \caption{figure}{This is caption}
        \end{framed}
    \end{center}
\end{figure}

\end{document}

Note that \captionsetup{labelfont={bf}} inside a figure environment is redundant: you have just called \captionsetup with this option.

In this case I suggest you to put \captionsetup in the preamble.

Note width=<value> in \captionsetup to set the width of your caption.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .