GeneralGeneral floating object with caption

LaTeX specific issues not fitting into one of the other forums of this category.
Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm

General floating object with caption

Post by Herder »

Hi,

is there a way to define a general floating object, for which one can define a border and a caption? All I want to do is having a sentence, which is centered, bordered and has a caption.

Thanks in advance,
Herder

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

General floating object with caption

Post by Stefan Kottwitz »

Hi Herder,

you could use the standard figure environment, like:

Code: Select all

\begin{figure}[ht]
\centering
\fbox{Text}
\caption{Test float}
\end{figure}
Alternatively the float package provides commands for the definition of new floating objects, it's boxed option could do what you are looking for.

Stefan
LaTeX.org admin
Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm

General floating object with caption

Post by Herder »

Hi Stefan_K,

this is exactly what I searched for, thanks.

But: Is there a way to omit the automatically generated prefix of the caption (e. g. "figure 1.3: text ...")? And can i define a own tag that will be used when referencing that figure?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

General floating object with caption

Post by Stefan Kottwitz »

Hi Herder,

have a look at the caption package, it is designed for the customization of captions, provides many features and is very well documented.

Stefan
LaTeX.org admin
Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm

General floating object with caption

Post by Herder »

Ok, combining the caption and float packages works well. There is only one little thing left, I don't get managed:

When i define my own floating object using the floatstyle "boxed", this boxed object always spans the whole site width. But i want it to dynamically adjust to its content, so that i don't have large boxes with only little content in it.

Let me illustrate it:

Now:

Code: Select all

-----------------------------------------------------
|                     Text                          |
-----------------------------------------------------
Wanted:

Code: Select all

-----------
|  Text   |
-----------
Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm

Re: General floating object with caption

Post by Herder »

Another drawback: the \label{} command doesn't seem to work in self-defined floats. There will be undefined references when referencing a label of such a float. Any idea how to fix this?
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

General floating object with caption

Post by gmedina »

Hi,

the following code (that uses nothing more than Stefan's suggestions) seems to do what you expect:

Code: Select all

\documentclass{article}
\usepackage{float}
\usepackage{caption}
\captionsetup{labelfont=bf,font=small}
\usepackage{lipsum}% just to automatically generate some text

\newfloat{Myfloat}{htbp}{myf}

\begin{document}

\begin{Myfloat}
  \centering
  \fbox{text}
  \caption{a simple example}
  \label{myf:test1}
\end{Myfloat}

\begin{Myfloat}
  \centering
  \fbox{\parbox{8cm}{\lipsum[1]}}
  \caption{another simple example}
  \label{myf:test2}
\end{Myfloat}

\newpage

Just a test. As you see in \ref{myf:test1}...

\newpage

And as you see in \ref{myf:test2}...

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm

General floating object with caption

Post by Herder »

That is exactly the way I use these packages. Is there a problem with setting references before the use of such a floating object? Example:

Code: Select all

Just a test. As you see in \ref{myf:test1}...

\begin{Myfloat}
  \centering
  \fbox{\parbox{8cm}{\lipsum[1]}}
  \caption{another simple example}
  \label{myf:test1}
\end{Myfloat}
Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm

Re: General floating object with caption

Post by Herder »

I just noticed, that all my references are undefined since I added the caption/float stuff.

Any ideas, why?
Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm

Re: General floating object with caption

Post by Herder »

I figured out, that it has something to do with the caption-package. Using the caption2-package solves the problem of having undefined references, but there is no way to format the captions of my freshly generated floating objects. Thus, the captions of the standard floats figure/table have another style than the captions of my own floats ... Arghhh, time consuming stuff ...
Post Reply