For Programmers: Free Programming Magazines  


Home > Archive > Tex > July 2006 > Improved float/caption syntax









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Improved float/caption syntax
Will Robertson

2006-07-26, 4:08 am

Hello,

Inspired by the discovery of floatrow's ability to nicely place
captions in relation to their floating material, I started thinking
about an improved syntax for these type of constructs. One thought I
had was that floats should eventually just take a bunch of keyval
arguments, including captions and label:
\begin{figure}
[type=float,
floatpos=htbp,
label=fig:mytestfig,
caption={Here's a\footnote{fragile} caption.},
shortcaption={Here's a caption.}]
....
\end{figure}

Other candidates for "type" could be "inset" (a la wrapfig) or "here"
(a la [H] for a regular float). Any others? ("inline"?)

Alternatively, and prompted by a vague recollection of some
documentation noting the behaviour of today's \caption, the \caption
command could be used as it is presently, and "moved out" from the
floating environment by typesetting everything in a box, like so:

\documentclass{article}
\makeatletter
\newsavebox\flbox
\newenvironment{myfig}
{\def\mycap##1{\gdef\@mycap{##1}}
\begin{lrbox}{\flbox}
\begin{minipage}{\linewidth}}
{\end{minipage}
\end{lrbox}\setfl}
\newcommand\setfl{%
\fbox{\begin{minipage}{\linewidth}
\textit{Caption}:~\@mycap\par\usebox\flb
ox
\end{minipage}}}
\begin{document}
\begin{myfig}
hello
\mycap{this is a caption}
\end{myfig}
\end{document}

For either case, a companion subfigure environment with the same syntax
would be defined. I.e., I don't like the syntax of the subfig command,
although I love the package otherwise.

Any discussion on the above points?
Or has someone already implemented all of this without my knowing (as
was the case with floatrow? :)

Will

Will Robertson

2006-07-26, 4:08 am

Will Robertson wrote:
> Or has someone already implemented all of this without my knowing (as
> was the case with floatrow? :)


It appears that Wybo Dekker's ctable package from 2005 does these
things for tables. Which is very nice. I guess I'm proposing a unified
interface for this kind of material in general, so the difference with
the ctable package would be that the various float options would be
handled within the optional args of the environment:

\begin{something?!?}
[kind=table,
type=float, % kind vs. type is too confusing; better names required
pos=htbp, % only if type=float
columnspec={@{}ccc@{}}, % only if kind=table
rowspec={}, % requires more thought
label=tab:testtab,
caption={A caption\footnote{that is fragile}.}
shortcaption={A caption.}]
1 & 2 & 3 \\
4 & 5 & 6
\end{something?!?}

Note that I suspect all the coding for these examples is fairly trivial
-- it's the interface I'm interested in. With the exception of a
"rowspec" argument -- that probably requires more programming design
than interface design.

Ulrike Fischer

2006-07-26, 8:03 am

"Will Robertson" <wspr81@gmail.com> schrieb:

> Hello,
>
> Inspired by the discovery of floatrow's ability to nicely place
> captions in relation to their floating material, I started thinking
> about an improved syntax for these type of constructs. One thought I
> had was that floats should eventually just take a bunch of keyval
> arguments, including captions and label:
> \begin{figure}
> [type=float,
> floatpos=htbp,
> label=fig:mytestfig,
> caption={Here's a\footnote{fragile} caption.},
> shortcaption={Here's a caption.}]


A figure can contain more than one caption (and label).
captions can also contain quite complicated code. So putting the
caption (and the label with it) in the argument is at my opinion not a
so good idea.



--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
Will Robertson

2006-07-26, 8:03 am

Ulrike Fischer wrote:
> A figure can contain more than one caption (and label).
> captions can also contain quite complicated code. So putting the
> caption (and the label with it) in the argument is at my opinion not a
> so good idea.


Hi Ulrike,

Thanks for your reply, I really appreciate it. Perhaps I'm being naive,
but can't (x)keyval input be saved to a macro without being expanded?
It's not like verbatims will work anyway, so I'm afraid I can't conjure
a hypothetical example that wouldn't fit into this idea. I deign to
your expertise, of course, however!

In case I need justification -- broadly speaking, the idea is to allow
for markup that is more "content-independent". I dislike the way, at
present, captions are typeset in fixed locations, and packages that
solve this problem do it with macros that take un-named arguments (also
like the subfig package).

Best regards,
Will

Ulrike Fischer

2006-07-26, 7:05 pm

"Will Robertson" <wspr81@gmail.com> schrieb:

> Ulrike Fischer wrote:
>
> Hi Ulrike,
>
> Thanks for your reply, I really appreciate it. Perhaps I'm being naive,
> but can't (x)keyval input be saved to a macro without being expanded?
> It's not like verbatims will work anyway, so I'm afraid I can't conjure
> a hypothetical example that wouldn't fit into this idea. I deign to
> your expertise, of course, however!
>
> In case I need justification -- broadly speaking, the idea is to allow
> for markup that is more "content-independent". I dislike the way, at
> present, captions are typeset in fixed locations, and packages that
> solve this problem do it with macros that take un-named arguments (also
> like the subfig package).


The problem is not so much with xkeyval or a technical one.

The main problem is that figure neither restrict the number nor the
position of captions. A figure is not an object with a caption. It is a
container that floats and which _can_ also contains one or more
captions. But captions are not different to other objects inside the
figure. You can use quite a lot captions in a figure at different
locations (e.g. in minipages, above a tabular, below a picture) in the
same way you can use quite a lot images or text in a figure.

If you put the caption in the argument of figure you will loose quite a
lot of flexibility. Look e.g. at such an example:

\documentclass [11pt, a4paper]{article}
\usepackage{caption}
\begin{document}
\begin{figure}
\begin{minipage}{0.4\textwidth}
\centering
\rule{1cm}{2cm}
\caption{a rule}
\end{minipage}
\begin{minipage}{0.4\textwidth}
\centering
\rule{2cm}{2cm}
\caption[short caption]{a second rule with a long explanation}
\end{minipage}

\captionof{table}{and now a caption above a tabular}
tabular
\end{figure}
\end{document}


For the same reason I don't like the "floatstyle" concept of float.sty.
It doesn't take into account that there is a difference between the
floating container and the object that gets a caption.

--
Ulrike Fischer
e-mail: zusätzlich meinen Vornamen vor dem @ einfügen.
e-mail: add my first name between the news and the @.
Will Robertson

2006-07-26, 7:05 pm

Hi Ulrike,

You wrote:
> If you put the caption in the argument of figure you will loose quite a
> lot of flexibility.


[snip nice example]

These are very good points, and I in fact agree with you. Thanks again.
While they don't invalidate the vague thoughts I have in my head, I can
definitely see where you're coming from based on my descriptions.
Apologies -- I have a terrible sickness! (Well, a terrible cold.)

> For the same reason I don't like the "floatstyle" concept of float.sty.
> It doesn't take into account that there is a difference between the
> floating container and the object that gets a caption.


For a counterexample: the current interface doesn't take into account
the difference between the floating container and what's contained
within it :) In short -- I'm not removing the concept of a generic
floating environment; in fact, I'm elevating it.

You might prefer something like:

\begin{float}[htbp]
\begin{figure}% non-floating!
figure one
\caption{fig 1}
\end{figure}
\begin{figure}% non-floating!
figure two
\caption{fig 2}
\end{figure}
\end{float}

(In the ideal case, even the placement of the two floats could be
declared beforehand without the need for explicit minipages. I think
floatrow does this, but I haven't taken a close look yet.)

I would also propose the convenient shorthand:

\begin{figure}[htbp]% floating! (another figure inside would be a
subfig, I guess)
figure three
\caption{fig 3}
\end{figure}

Although at this stage I think I prefer the optional argument syntax to
denote the caption.
I hope you don't tire of the discussion -- any further/concluding
thoughts?

All the best,
Will

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com