Theses, Books, Title pagesUsing images inside Theorems

Classicthesis, Bachelor and Master thesis, PhD, Doctoral degree
Post Reply
templateuser
Posts: 679
Joined: Tue Mar 03, 2015 4:01 pm

Using images inside Theorems

Post by templateuser »

Hi!
First of all, congratulations and thanks to the creator of this template. It is awesome!!
And here goes my question... Is it possible to include images inside the Theorem environment (or definition, or exercise...)? When I simply put the image inside it the regular way (ie, \begin{figure} \include{graphics}...) I always get the same error: "Lost float"
Many thanks in advance!! Any help will be much appreciated.
Cheers

the_blue_note

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
Vel
Site Moderator
Posts: 463
Joined: Fri Jun 29, 2012 1:20 am

Using images inside Theorems

Post by Vel »

Hi,

Putting a float inside a float gives an error as you have said in your post, which means you can't use the figure environment within the theorem environment. Luckily, there is a workaround you can use which is to refrain from using the figure environment and print the caption using the caption package. To do this, you will need to include the caption package in the preamble with \usepackage{caption} and then to include a figure within a theorem, use the following example:

Code: Select all

\begin{theorem}[Name of the theorem]
~\\[12pt]
\includegraphics[scale=0.5]{placeholder}
\captionof{figure}{Caption for image}
In $E=\mathbb{R}^n$ all norms are equivalent. It has the properties:
\begin{align}
& \big| ||\mathbf{x}|| - ||\mathbf{y}|| \big|\leq || \mathbf{x}- \mathbf{y}||\\
&  ||\sum_{i=1}^n\mathbf{x}_i||\leq \sum_{i=1}^n||\mathbf{x}_i||\quad\text{where $n$ is a finite integer}
\end{align}
\end{theorem}
Cheers,
Vel
Founder and administrator of LaTeXTemplates.com and LaTeXTypesetting.com
templateuser
Posts: 679
Joined: Tue Mar 03, 2015 4:01 pm

Re: Using images inside Theorems

Post by templateuser »

Thank you, thank you, thank you!! =)
PS: How do I mark this as closed...?
User avatar
Vel
Site Moderator
Posts: 463
Joined: Fri Jun 29, 2012 1:20 am

Re: Using images inside Theorems

Post by Vel »

You're welcome :)

I usually leave these open so others can come along later and ask further questions on the same topic or add further solutions.
Founder and administrator of LaTeXTemplates.com and LaTeXTypesetting.com
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Using images inside Theorems

Post by Johannes_B »

Instead of putting a \newline, i suggest to use a proper paragraph break, maybe even along with a center environment.

Code: Select all

\documentclass{book}
\usepackage{caption}
\usepackage{mathtools}
\usepackage{mwe}
\usepackage{amssymb}
\usepackage{physics}
\newtheorem{theorem}{Theorem}
\begin{document}
\begin{theorem}[Name of the theorem]~
	\begin{center}
	\includegraphics[width=.6\linewidth]{example-image-a}
	\captionof{figure}{Caption for image}
\end{center}
	In $E=\mathbb{R}^n$ all norms are equivalent. It
	has the properties:
	\begin{align}
		& \big| ||\mathbf{x}|| - ||\mathbf{y}||
		\big|\leq || \mathbf{x}- \mathbf{y}||\\
		& ||\sum_{i=1}^n\mathbf{x}_i||\leq
		\sum_{i=1}^n||\mathbf{x}_i||\quad\text{where
		$n$ is a finite integer}
	\end{align}
\end{theorem}
\end{document}
The math could use a lot of polishing using packages like physics and semantic markup as well.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
Post Reply