1

The following MWE doesn't compile if I uncomment the commented lines:

\documentclass[a4paper,10pt]{book}

\usepackage{amsmath}
\usepackage{mdframed}
\usepackage{graphicx}
\usepackage{xcolor}

\mdfdefinestyle{theoremSty}{backgroundcolor=yellow!10, linewidth=0pt, innerleftmargin=3ex, innerrightmargin=3ex, innertopmargin=1ex, innerbottommargin=1ex, innermargin =+1cm, outermargin =+1cm}
\newcounter{theoremCounter}[chapter]
\numberwithin{theoremCounter}{chapter}
\newmdtheoremenv[style=theoremSty]{theorem}[theoremCounter]{Theorem}

\begin{document}

\begin{theorem}

\lipsum[1]

%\begin{figure}
  \includegraphics[width=0.6\linewidth]{example-image-a}
%  \caption{Example image A.}
%  \label{fig:example-image-a}
%\end{figure}

\lipsum[2]

\end{theorem}

\end{document}

The question is why can't I put the figure inside the theorem and if there is a workaround.

(I've checked that the figure works outside the theorem.)

1
  • 2
    You can have picture inside theorem, however not as float! The float figure is intended for move around in a text (therefore name float), what can not do inside theorem. If you like have the caption, than use caption-of from package caption or small package `capt-of``.
    – Zarko
    Commented Jan 29, 2016 at 14:20

1 Answer 1

5

It is possible with \usepackage{floatrow} that defines a new Option H for \begin{figure}[H].

With this, the figure is not floating and just placed where you include it.

You can use caption and label like for floating figures.

\documentclass[a4paper,10pt]{book}

\usepackage{amsmath}
\usepackage{mdframed}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{floatrow}
\usepackage{lipsum}


\mdfdefinestyle{theoremSty}{backgroundcolor=yellow!10, linewidth=0pt, innerleftmargin=3ex, innerrightmargin=3ex, innertopmargin=1ex, innerbottommargin=1ex, innermargin =+1cm, outermargin =+1cm}
\newcounter{theoremCounter}[chapter]
\numberwithin{theoremCounter}{chapter}
\newmdtheoremenv[style=theoremSty]{theorem}[theoremCounter]{Theorem}

\begin{document}

\begin{theorem}

\lipsum[1]

\begin{figure}[H]
%  \includegraphics[width=0.6\linewidth]{example-image-a}
  THE IMAGE
  \caption{Example image A.}
  \label{fig:example-image-a}
\end{figure}

\lipsum[2]

\end{theorem}

Have a look at fig. \ref{fig:example-image-a}.

\end{document}

document

You must log in to answer this question.

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