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

Postby Herder » Wed Aug 13, 2008 10:21 am

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

User avatar
Stefan Kottwitz
Site Admin
Posts: 9604
Joined: Mon Mar 10, 2008 9:44 pm

Postby Stefan Kottwitz » Wed Aug 13, 2008 2:56 pm

Hi Herder,

you could use the standard figure environment, like:
  1. \begin{figure}[ht]
  2. \centering
  3. \fbox{Text}
  4. \caption{Test float}
  5. \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

Postby Herder » Thu Aug 14, 2008 10:35 am

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

Postby Stefan Kottwitz » Thu Aug 14, 2008 2:21 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
LaTeX.org admin

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

Postby Herder » Thu Aug 14, 2008 4:00 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:
  1. -----------------------------------------------------
  2. | Text |
  3. -----------------------------------------------------

Wanted:
  1. -----------
  2. | Text |
  3. -----------

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

Postby Herder » Thu Aug 14, 2008 4:23 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?

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

Postby gmedina » Fri Aug 15, 2008 12:15 am

Hi,

the following code (that uses nothing more than Stefan's suggestions) seems to do what you expect:
  1. \documentclass{article}
  2. \usepackage{float}
  3. \usepackage{caption}
  4. \captionsetup{labelfont=bf,font=small}
  5. \usepackage{lipsum}% just to automatically generate some text
  6.  
  7. \newfloat{Myfloat}{htbp}{myf}
  8.  
  9. \begin{document}
  10.  
  11. \begin{Myfloat}
  12. \centering
  13. \fbox{text}
  14. \caption{a simple example}
  15. \label{myf:test1}
  16. \end{Myfloat}
  17.  
  18. \begin{Myfloat}
  19. \centering
  20. \fbox{\parbox{8cm}{\lipsum[1]}}
  21. \caption{another simple example}
  22. \label{myf:test2}
  23. \end{Myfloat}
  24.  
  25. \newpage
  26.  
  27. Just a test. As you see in \ref{myf:test1}...
  28.  
  29. \newpage
  30.  
  31. And as you see in \ref{myf:test2}...
  32.  
  33. \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

Postby Herder » Fri Aug 15, 2008 8:43 am

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:

  1. Just a test. As you see in \ref{myf:test1}...
  2.  
  3. \begin{Myfloat}
  4. \centering
  5. \fbox{\parbox{8cm}{\lipsum[1]}}
  6. \caption{another simple example}
  7. \label{myf:test1}
  8. \end{Myfloat}

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

Postby Herder » Fri Aug 15, 2008 10:37 am

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

Postby Herder » Fri Aug 15, 2008 11:10 am

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


Return to “General”

Who is online

Users browsing this forum: No registered users and 10 guests