[Tex/LaTex] How to frame a figure in Lyx

floatslyx

I use Lyx 2.1.
I want to frame the figures. I inserted a simple box and I put the figure inside it.

But, I encountered these errors :

enter image description here

Best Answer

Three different ways, for three different scenarios.

1. Frame tightly enclosing image

Step by step:

  1. Add a Figure float, with Insert --> Float --> Figure, or the enter image description here button on the toolbar.

  2. Add a framebox with Insert --> Box --> Simple frame inside the Figure float.

  3. Right click the box and choose Settings.

  4. Set the Inner box to None, and remove the checkmark from the Width box:

    enter image description here

  5. Insert the image inside this box, with Insert --> Graphics or the enter image description here button on the toolbar.

enter image description here

2. Just image inside frame, frame width of the text

If the caption should not be inside the frame, go to Document --> Settings --> LaTeX preamble, and add the following:

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

This will make all your figures (added with Insert --> Float --> Figure, or the corresponding button on the toolbar) framed.

enter image description here

If you want the caption a little further away from the frame in this case, replace the three code lines above with

\usepackage{float}
\renewcommand\fs@boxed{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@plain
  \def\@fs@pre{\setbox\@currbox\vbox{\hbadness10000
    \moveleft3.4pt\vbox{\advance\hsize by6.8pt
      \hrule \hbox to\hsize{\vrule\kern3pt
        \vbox{\kern3pt\box\@currbox\kern3pt}\kern3pt\vrule}\hrule}}}%
  \def\@fs@mid{\vspace{\abovecaptionskip}}%
  \def\@fs@post{}\let\@fs@iftopcapt\iffalse}

\floatstyle{boxed} 
\restylefloat{figure}

3. Both caption and image inside frame

You can use Peter Grill's answer to Rounded corner colored box around figure. For a simple black frame, and add this code to the LaTeX preamble:

\usepackage{float}
\usepackage[framemethod=tikz]{mdframed}

\mdfdefinestyle{myFigureBoxStyle}{tikzsetting={draw=black, line width=1pt}}%

 \newcommand\fs@myRoundBox{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@plain
  \def\@fs@pre{\begin{mdframed}[style=myFigureBoxStyle]}%
  \def\@fs@mid{\vspace{\abovecaptionskip}}%
  \def\@fs@post{\end{mdframed}}\let\@fs@iftopcapt\iffalse}

\floatstyle{myRoundBox} 
\restylefloat{figure}

This will make figures, including the caption, framed.

enter image description here

Related Question