The rotfloat package^{∗}

Axel Sommerfeldt

                rotfloat@sommerfeldt.net

2004/01/04

Abstract The float package [1] provides commands to define new floats of various styles (plain, boxed, ruled, and userdefined ones); the rotating package [2] provides new environments (sidewaysfigure and sidewaystable) which are rotated by 90^{∘} or 270^{∘}. But what about new rotated floats, e.g. a rotated ruled one? This package makes this possible; it builds a bridge between both packages and extend the commands from the float package to define rotated versions of the new floats, too.

1 The user interface

To use this package just put the line

     \usepackage[⟨options⟩]{rotfloat}

into the preamble of your document. The options are exactly the same as for the rotating package, because all options will be passed to the rotating package. (The rotfloat package hasn’t got any own options at all).

\newfloat The commands \newfloat and \restylefloat from the float package (re)define \restylefloat the float type ⟨type⟩ and now additionally a rotated one called ⟨sidewaystype⟩:

\newfloat{⟨type⟩}{⟨placement⟩}{⟨ext⟩}[⟨within⟩]

     \restylefloat{⟨type⟩}

E.g. the code

     \floatstyle{ruled}
     \floatname{program}{Program}
     \newfloat{program}{tbp}{lop}[section]

defines the new floating environments program, program*, sidewaysprogram,

and sidewaysprogram* which behave equivalent to figure, figure*,
sidewaysfigure, and sidewaysfigure*. (Note that sidewaysfigure* has been

introduced to version 2.10 of the rotating package, therefore you only get a sidewaysprogram* environment if you use this or a newer version of the rotating package.)

∗This package has version number 1.2, last revised 2004/01/04.

The code

     \floatstyle{boxed}
     \restylefloat{table}

will restyle the environments table, table*, sidewaystable, and

sidewaystable*.

Please take a look at the float package for a complete description of these commands. Additionally an example file is provided with this package.

2 What has changed since version 1.0?

Version 1.0 of this package was a quick & dirty hack. The version 1.1 took it all more serious, it patched less code from the float package and especially it let the [H] code for the not-sideways floats intact. Furthermore it was adapted to the new version 1.3 of the float and 2.10 of the rotating package. This version 1.2 is a further step in this direction. It was revised again to make it even more compatible to different versions of the float package. As an effect of this [H] for sideways floats is now fully supported (this could be desirable when used in cooperation with the afterpage package), furthermore a bug was fixed that caused problems if the rotfloat package was used together with the color package.

3 A final note

This package was tested with the versions 1.2, 1.2c, 1.2d, 1.2e, 1.3c, and 1.3d of the float package and version 2.6, 2.9, 2.10, 2.12, and 2.13 of the rotating package. You should not use this package together with older versions of them! Future versions of these packages may make some trouble, but I hope they will not. If they do please don’t hesitate to send me a bug report including a simple nonworking example and the log file produced by L^{A}TEX.

4 Further reading

I recommend the following documents for further reading:

• The TEX FAQ - Frequently asked questions about TEX and L^{A}TEX:

         http://faq.tug.org/

• A French FAQ can be found at

         http://www.grappa.univ-lille3.fr/FAQ-LaTeX/

• A German FAQ can be fount at

         http://www.dante.de/faq/de-tex-faq/

• epslatex from Keith Reckdahl contains many tips around graphics in L^{A}TEX 2ε. You will find this document in the directory

         ftp://ftp.ctan.org/pub/tex/info/
     as epslatex.ps and epslatex.pdf.

There is also a french translation available at

         ftp://ftp.ctan.org/pub/tex/info/fepslatex.ps

• “Gleitobjekte – die richtige Schmierung” from Axel Reichert is a German documentation about floating environments in general. You will find it here:

         ftp://ftp.ctan.org/pub/tex/info/german/gleitobjekte/

5 Thanks

I would like to thank Katja Melzner, Anselm Lingnau, Sebastian Rahtz, and Wojciech Pietron.

6 The code

Note: If you really want to know what’s exactly going on here, you have to study the code from the packages float and rotating first!

6.1 The identification part

 1 \NeedsTeXFormat{LaTeX2e}[1995/12/01]
 2 \ProvidesPackage{rotfloat}[2004/01/04 v1.2 Combining float+rotating package (AS)]

6.2 The package loading part

Of course this package needs the float and the rotating package, so we load them both here. (The rotfloat package hasn’t got any own options, so we just pass everything we get to the rotating package.)

 3 \RequirePackage{float}[1994/06/20]      % >= version 1.2
 4 \RequirePackageWithOptions{rotating}%[1995/01/06]  % >= version 2.6

6.3 Adaption of the float package

We have different code for version 1.2 and version 1.3 of the float package. If \@float@HH is not defined we assume version 1.2, otherwise version 1.3.

 5 \ifx\@float@HH\undefined
 6 \PackageInfo{rotfloat}{float package v1.2 detected}

First the code for version 1.2 of the float package:

\restylefloat The new code for \restylefloat behaves like the old one, but it defines a sideways float as well. If \@rotdblfloat is defined we have loaded rotating version 2.10 or newer. In this case we can define a star form as well.

 7 \let\rotfloat@restyle\restylefloat
 8 \renewcommand*\restylefloat[1]{%
 9  \rotfloat@restyle{#1}%
10  \@namedef{sideways#1}{\rotfloat@float{#1}}%

11  \expandafter\let\csname endsideways#1\endcsname\float@end
12  \ifx\@rotdblfloat\@undefined
13  \else
14  \@namedef{sideways#1*}{\rotfloat@dblfloat{#1*}}%
15  \expandafter\let\csname endsideways#1*\endcsname\float@dblend
16  \fi}

\rotfloat@float What differs sideways floats from ‘normal’ ones?

1. \hsize, \textwidth, and \columnwidth are set to \textheight. Usually

this is done in \@xrotfloat (rotating package) but this time we have to do it for ourself because the float package handles floats differently:

It collects its contents (= \@currbox) first, so it can build up a new float contents (including the current one) later on. This step is neccessary because the float package will take care of the placement of the \caption. Furthermore it can add rules, boxes and so on here, whatever the actual float style wants to. (This is done in \float@makebox.)

Note that we don’t set \hsize here, because \@xfloat (part of L^{A}TEX) will

set \hsize to \columnwidth anyway.

2. We build up the float contents with \rotfloat@makebox (instead of \float@makebox) which rotates the contents additionally.

17 \newcommand\rotfloat@float{%
18  \textwidth\textheight
19  \columnwidth\textheight
20  \let\rotfloat@@makebox\float@makebox
21  \let\float@makebox\rotfloat@makebox
22  \@nameuse}
\rotfloat@dblfloat For double column floats we use \rotdblfloat@makebox here.
23 \newcommand\rotfloat@dblfloat{%
24  \textwidth\textheight
25  \columnwidth\textheight
26  \let\rotfloat@@makebox\float@makebox
27  \let\float@makebox\rotdblfloat@makebox
28  \@nameuse}

\@HHfloat For sideways floats with a placement specifier [H] the original code of \@HHfloat from the float package is sufficient. But we have to take care that at the end of the float \rotfloat@endH will be called instead of \float@endH so we can handle them correctly later on.

29 \let\rotfloat@HH\@HHfloat
30 \def\@HHfloat#1{%
31  \expandafter\let\csname endsideways#1\endcsname\rotfloat@endH
32 %   \expandafter\let\csname endsideways#1*\endcsname\rotfloat@dblendH
33  \let\end@float\relax
34  \rotfloat@HH{#1}}

\rotfloat@endH The float package defines this command to close a floating environment with a [H] placement specifier:

     \newcommand\float@endH{%
       \egroup (or \@endfloatbox)
       \vskip\intextsep
       \if@flstyle\float@makebox\egroup\else\box\@currbox\fi
       \vskip\intextsep\relax}

The \egroup (or \@endfloatbox) will close the \@currbox first. Afterwards the contents of the float will be typeset HERE, surrounded by some extra skip. If

the float was defined with \newfloat or \restylefloat, \float@makebox will be

used to build up the float contents. (An extra \egroup is needed to finish off the \bgroup that precedes the \@nameuse in the \begin{⟨float⟩} commands. See the code documentation of the float package v1.2 for details.) Otherwise the vanilla \@currbox will be used. Here comes our version: If the float was defined with \newfloat or \restylefloat (that means \if@flstyle is true) we can use the original code from the float package because \float@makebox was replaced with \rotfloat@makebox anyway. (See our definition of \rotfloat@float for details.) But if this is not the case (that means \if@flstyle is false) we have to close the rotated float first. This is usually done with \end@rotfloat (which is part of the rotating package) but there is a caveat: \end@rotfloat uses \end@float which normally closes a floating environment. But we don’t want to support floating here (well, that’s why the user has specified the placement [H]), so we re-define \end@float to \relax which does simply nothing. (Note that this re-definition takes place in \@HHfloat because \end@rotfloat closes some environments first, so our re-definition would get lost if we would make it here.) Afterwards the original code from the float package (= \float@endH) is sufficient again.

35 \newcommand\rotfloat@endH{%
36  \if@flstyle
37  \else
38 %     \let\end@float\relax
39  \end@rotfloat
40  \fi
41  \float@endH}

\rotfloat@makebox Finally: The typesetting of a (re-styled) rotated float. This is quite simple: We put the \float@makebox inside a rotated environment. For this purpose we use \@rotfloat and \end@rotfloat which usually begin and end a rotated floating environment; they are provided by the rotating package. But we have to keep the floating stuff outside, so we define \@float (which is

used by \@rotfloat) and \end@float (which is used by \end@rotfloat) to do

nothing.

42 \newcommand\rotfloat@makebox{%
43  \vbox{%
44  \def\@float##1[##2]{}\let\end@float\relax
45  \@rotfloat{}[]%
46  \rotfloat@@makebox
47  \end@rotfloat}}

\rotdblfloat@makebox Well, this is quite the same as \rotfloat@makebox but we use the appropriate macros for the star-variants of floating environments here.

48 \newcommand\rotdblfloat@makebox{%

49  \vbox{%
50  \def\@float##1[##2]{}\let\end@dblfloat\relax
51  \@rotdblfloat{}[]%
52  \rotfloat@@makebox
53  \end@rotdblfloat}}

So far the code for the version 1.2 of the float package.

54 \else

Now the code for the float package version 1.3: It is mainly the same, so we only tell you the small differences compared to the code inside the branch for the float package version 1.2 here.

55 \PackageInfo{rotfloat}{float package v1.3 detected}
\float@restyle We have to extend \float@restyle instead of \restylefloat here, so \restylefloat*

will still work.

56 \let\rotfloat@restyle\float@restyle
57 \renewcommand*\float@restyle[1]{%
58  \rotfloat@restyle{#1}%
59  \@namedef{sideways#1}{\rotfloat@float{#1}}%
60  \expandafter\let\csname endsideways#1\endcsname\float@end
61  \ifx\@rotdblfloat\@undefined
62  \else
63  \@namedef{sideways#1*}{\rotfloat@dblfloat{#1*}}%
64  \expandafter\let\csname endsideways#1*\endcsname\float@dblend
65  \fi}
\rotfloat@float \rotfloat@dblfloat These two don’t have to be changed.
66 \newcommand\rotfloat@float{%
67  \textwidth\textheight
68  \columnwidth\textheight
69  \let\rotfloat@@makebox\float@makebox
70  \let\float@makebox\rotfloat@makebox
71  \@nameuse}
72 \newcommand\rotfloat@dblfloat{%
73  \textwidth\textheight
74  \columnwidth\textheight
75  \let\rotfloat@@makebox\float@makebox
76  \let\float@makebox\rotdblfloat@makebox
77  \@nameuse}
\@float@HH We have to extend \@float@HH instead of \@HHfloat here.
78 \let\rotfloat@HH\@float@HH
79 \def\@float@HH#1{%
80  \expandafter\let\csname endsideways#1\endcsname\rotfloat@endH
81 %   \expandafter\let\csname endsideways#1*\endcsname\rotfloat@dblendH
82  \let\end@float\relax
83  \rotfloat@HH{#1}}

\rotfloat@endH This one hasn’t to be changed.

84 \newcommand\rotfloat@endH{%
85  \if@flstyle
86  \else

87 %     \let\end@float\relax
88  \end@rotfloat
89  \fi
90  \float@endH}
\rotfloat@makebox \rotdblfloat@makebox  \float@makebox has a parameter here which will be set to \columnwidth or

\textwidth. (In the float package v1.2 the \columnwidth was hard wired into \float@makebox.) So we have to pass this parameter through the original ver-

sion of \float@makebox which we have saved to \rotfloat@@makebox within
\rotfloat@float.)
91 \newcommand*\rotfloat@makebox[1]{%
92  \vbox{%
93  \def\@float##1[##2]{}\let\end@float\relax
94  \@rotfloat{}[]%
95  \rotfloat@@makebox{#1}%
96  \end@rotfloat}}
97 \newcommand*\rotdblfloat@makebox[1]{%
98  \vbox{%
99  \def\@float##1[##2]{}\let\end@dblfloat\relax
100  \@rotdblfloat{}[]%
101  \rotfloat@@makebox{#1}%
102  \end@rotdblfloat}}

That’s all folks.

103 \fi

References

[1] Anselm Lingnau: An Improved Environment for Floats, 2001/11/08

[2] Sebastian Rahtz and Leonor Barroca: A style option for rotated objects in L^{A}TEX, 1997/09/26