## LaTeX forum ⇒ General ⇒ General 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

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.

Herder

Stefan Kottwitz
Posts: 9604
Joined: Mon Mar 10, 2008 9:44 pm
Hi Herder,

you could use the standard figure environment, like:
\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

Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm
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?

Stefan Kottwitz
Posts: 9604
Joined: Mon Mar 10, 2008 9:44 pm
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

Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm
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:
-----------------------------------------------------|                     Text                          |-----------------------------------------------------

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

Herder
Posts: 16
Joined: Tue Aug 05, 2008 2:32 pm
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?

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm
Hi,

the following code (that uses nothing more than Stefan's suggestions) seems to do what you expect:
\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
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:

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
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
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 ...