Graphics, Figures & TablesTextbox with multiple figures and/or tables

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
mippes
Posts: 8
Joined: Tue Jan 05, 2010 3:29 pm

Textbox with multiple figures and/or tables

Post by mippes »

Hi,
At the moment I am writing a thesis and I want to make an 'intermezzo' block, where I can write text, add figures and tables. I tried several things, e.g. \fbox,\colorbox, and \parbox, but it becomes problematic when I want to add multiple figures in the same textbox. With one figure or table you can avoid problems by putting the \begin{figure} outside the \fbox, but this I can't do if I want more than one figure in the intermezzo block.

Does anyone knows how to do this. It must be a frequently asked question, but cannot find it on the internet.

Thanks,
Miriam

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Textbox with multiple figures and/or tables

Post by Stefan Kottwitz »

Hi Miriam,

you cannot use figures or tables in a box since they are floating objects. In the box, directly use \includegraphics and tabular etc.

If you need captions, you could use the caption package and its command \captionof, such as

Code: Select all

\usepackage{caption}
% or customized captions, such as
% \usepackage[margin=10pt,font=small,labelfont=bf]{caption}
...
\begin{framed}% or any box
...
\begin{center}
  \begin{minipage}{\linewidth}
  \centering
  \includegraphics{filename}
  \captionof{figure}{Description}
  \label{fig:10}
  \end{minipage}
\end{center}
...
\end{framed}
Stefan
LaTeX.org admin
mippes
Posts: 8
Joined: Tue Jan 05, 2010 3:29 pm

Re: Textbox with multiple figures and/or tables

Post by mippes »

Hi Stefan,
Thank you for your answer. It indeed works when you only have one figure of table. But I would like to have multiple figures in the framed box.

Furthermore, by using the caption package, LaTeX is now giving errors for all the other figures since there I only use \caption{blahblah}. According to the package documentation you have to define for every caption if it is a figure or a table. This is quite a lot of work. Do you know a smarter way for this??

Regards,
Miriam
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Textbox with multiple figures and/or tables

Post by sommerfee »

mippes wrote:Furthermore, by using the caption package, LaTeX is now giving errors for all the other figures
What errors do you get? Could you please tell us the very first one?
since there I only use \caption{blahblah}.
This is (of course) still ok, if typeset inside a floating environment. Otherwise you'll get an error, but this is true when not using the caption package, too.
According to the package documentation you have to define for every caption if it is a figure or a table.
This is not the case. Where exactly have you read this? :shock:

Or do you mean \captionof? You don't have to use it, as an alternative one can use \captionsetup{type=figure}, e.g.:

Code: Select all

\usepackage{caption}
% or customized captions, such as
% \usepackage[margin=10pt,font=small,labelfont=bf]{caption}
...
\begin{framed}% or any box
...
\begin{center}
  \begin{minipage}{\linewidth}
  \captionsetup{type=figure}
  \centering
  \includegraphics{filename}
  \caption{Description}
  \label{fig:10}
  ...
  \end{minipage}
\end{center}
...
\end{framed}
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Textbox with multiple figures and/or tables

Post by sommerfee »

Additionally, I have a question about your initial post:
mippes wrote:With one figure or table you can avoid problems by putting the \begin{figure} outside the \fbox, but this I can't do if I want more than one figure in the intermezzo block.
Why can't you do that?
mippes
Posts: 8
Joined: Tue Jan 05, 2010 3:29 pm

Textbox with multiple figures and/or tables

Post by mippes »

The errors I get, when I don't change anything, but only add the package (\usepackage{caption}) and even not add any frames:
! Undefined control sequence.
\captionlabelfont@default ->\cph@font

l.6 \caption{The hydrological cycle.}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
The comment on the errors is in Section 2.9 of http://archive.cs.uu.nl/mirror/CTAN/mac ... on-eng.pdf
mippes
Posts: 8
Joined: Tue Jan 05, 2010 3:29 pm

Textbox with multiple figures and/or tables

Post by mippes »

Concerning the question on why I cannot put the \begin{figure} outside frame:

E.g. if I do:

Code: Select all

\begin{figure}
   \begin{framed}
        \includegraphics{..}
        \caption{blahblah}
   \end{framed}
\end{figure}
\begin{figure}
   \begin{framed}
       \includegraphics{...figure2}
       \caption{blahblah}
   \end{framed}
\end{figure}
Then it is considered as two blocks/floats. Problem is then that the text from the main text is coming in between the intermezzo blocks. Even if I force the framed box to be located [h!]
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Textbox with multiple figures and/or tables

Post by sommerfee »

mippes wrote:! Undefined control sequence.
\captionlabelfont@default ->\cph@font
It seems that your document class is called "thesis". In this case older versions of the caption package assumed that you are using the thesis document class from CTAN. This was fixed in version 3.1l of the caption package.

So either update your caption package, or place the following code after loading the caption package:

Code: Select all

  \captionsetup{format=plain,labelfont=,textfont=}
Regarding the figures and the frames: Why don't you simple put multiple images inside the figure environment, e.g.:

Code: Select all

\begin{figure}
   \begin{framed}
        \includegraphics{..}
        \caption{blahblah}
   \end{framed}
   \begin{framed}
       \includegraphics{...figure2}
       \caption{blahblah}
   \end{framed}
\end{figure}
or

Code: Select all

\begin{figure}
   \begin{framed}
        \includegraphics{..}
        \caption{blahblah}
       \medskip
       \includegraphics{...figure2}
       \caption{blahblah}
   \end{framed}
\end{figure}
Post Reply