General ⇒ General floating object with caption
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.
Thanks in advance,
Herder
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
- Stefan Kottwitz
- Site Admin
- Posts: 10290
- Joined: Mon Mar 10, 2008 9:44 pm
General floating object with caption
Hi Herder,
you could use the standard figure environment, like:
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
you could use the standard figure environment, like:
Code: Select all
\begin{figure}[ht]
\centering
\fbox{Text}
\caption{Test float}
\end{figure}
Stefan
LaTeX.org admin
General floating object with caption
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?
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
- Site Admin
- Posts: 10290
- Joined: Mon Mar 10, 2008 9:44 pm
General floating object with caption
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
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
General floating object with caption
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:
Wanted:
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 |
-----------------------------------------------------
Code: Select all
-----------
| Text |
-----------
Re: General floating object with caption
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?
General floating object with caption
Hi,
the following code (that uses nothing more than Stefan's suggestions) seems to do what you expect:
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,...
General floating object with caption
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}
Re: General floating object with caption
I just noticed, that all my references are undefined since I added the caption/float stuff.
Any ideas, why?
Any ideas, why?
Re: General floating object with caption
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 ...