The rotfloat package^{∗}

Axel Sommerfeldt

                rotfloat@sommerfeldt.net

2002/02/02

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 type

     \usepackage[⟨options⟩]{rotfloat}

in 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⟩:

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

     \restylerotfloat{⟨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.1, last revised 2002/02/02.

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 but working hack. This version takes it all more serious, it tries to patch as less code from the float package as possible and especially it lets the [H] code for the not-sideways floats intact. (Version 1.0 had just patched [H] to [!ht] to make thinks easier to handle.) Furthermore it was adapted to the new versions 1.3 of the float and 2.10 of the rotating 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 logfile produced by TeX.

4 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!

4.1 The identification part

 1 \NeedsTeXFormat{LaTeX2e}[1994/12/01]
 2 \ProvidesPackage{rotfloat}[2002/02/02 v1.1 rotfloat package (AS)]
 3 \typeout{Package: rotfloat v1.1 <2002/02/02> (Axel Sommerfeldt)}

4.2 The declaration and execution of options

The rotfloat package hasn’t got any own options, so we just pass everything we get to the rotating package.

 4 \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{rotating}}
 5 \ProcessOptions

4.3 The package loading part

Of course this package needs the float and the rotating package, so we load them both here.

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

4.4 Adaption of the float package

\rotfloat@xoftwo If the float is a normal one, \rotfloat@xoftwo is defined to \@firstoftwo. If it

is a sideways one, it will be (locally) defined to \@secondoftwo.

 8 \let\rotfloat@xoftwo\@firstoftwo

From now on 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.

 9 \ifx\@float@HH\undefined
10 \wlog{rotfloat package: v1.2 of float detected}

First the code for version 1.2 of the float package:

\rotfloat@HH \rotfloat@restyle We save the old definitions of \@HHfloat and \restylefloat because we need

them later on.

11 \let\rotfloat@HH\@HHfloat
12 \let\rotfloat@restyle\restylefloat

\@HHfloat We do not support the placement specifier [H] for sideways floats, therefore we have to patch it to [!ht] if it is a sideways one.

13 \def\@HHfloat#1[H]{%
14  \rotfloat@xoftwo{\rotfloat@HH{#1}[H]}{\@Hxfloat{#1}[!ht]}}

\restylefloat The new code for \restylefloat behaves like the old one, but it defines a sideways float as well. What differs sideways floats from the ‘normal’ ones?

  1. \rotfloat@xoftwo is defined to \@secondoftwo. (\rotfloat@xoftwo will

be used in \@HHfloat.)

  2. \columnwidth ist set to \textheight before calling \@float. (\@float
     itself set \hsize to \columnwidth.)
  3. \rotfloat@end is used instead of \float@end.

If \@rotdblfloat is defined we have included rotating version 2.10 or newer. In this case we can define a star form as well. Otherwise we define a star form, too, but this causes an error and will do the non-star form instead.

15 \renewcommand*\restylefloat[1]{%
16  \rotfloat@restyle{#1}%
17  \@namedef{sideways#1}{%
18  \let\rotfloat@xoftwo\@secondoftwo\columnwidth\textheight
19  \@nameuse{fst@#1}\@float{#1}}%
20  \expandafter\let\csname endsideways#1\endcsname\rotfloat@end
21  \ifx\@rotdblfloat\undefined

22  \@namedef{sideways#1*}{%
23  \PackageError{rotfloat}{%
24  You need rotating version 2.10 or newer to do this}{\@ehd}%
25  \@nameuse{sideways#1}}%
26  \expandafter\let\csname endsideways#1*\endcsname\rotfloat@end
27  \else
28  \@namedef{sideways#1*}{%
29  \let\rotfloat@xoftwo\@secondoftwo\columnwidth\textheight
30  \@nameuse{fst@#1}\@dblfloat{#1}}%
31  \expandafter\let\csname endsideways#1*\endcsname\rotfloat@dblend
32  \fi}

\rotfloat@end \rotfloat@dblend To understand the following code we first have to understand what is going on inside \float@end. Well, mainly it looks like this:

     \newcommand\float@end{%
       \egroup
       \global\setbox\@currbox\vbox\bgroup
       \float@makebox\end@float\egroup}

The \egroup will finish the current definition of the float inside the vbox \@currbox. Afterwards the float is redefined to \float@makebox (which will build up a new float contents) plus \end@float (which will mainly finish the definition of the new float with \egroup). The \egroup finally closes the group which started at the beginning of the environment (see \restylefloat). These macros now do the same, but instead of using \float@makebox plus \end@float we set the new float contents to

1. \@rotfloat (but without the contents of the \@float itself)

2. \float@makebox (which includes the contents of the float)

  3. \end@rotfloat (which includes \egroup)

Note that we do not need the final \egroup here, because we do not start our sideways environments with an extra \bgroup.

33 \newcommand*\rotfloat@end{%
34  \egroup%
35  \global\setbox\@currbox\vbox\bgroup%
36  \def\@float##1[##2]{}\let\@xfloat\@float\@rotfloat{}%
37  \float@makebox\end@rotfloat}
38 \newcommand*\rotfloat@dblend{%
39  \egroup%
40  \global\setbox\@currbox\vbox\bgroup%
41  \def\@float##1[##2]{}\let\@xfloat\@float\@rotdblfloat{}%
42  \float@makebox\end@rotdblfloat}

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

43 \else

Now the code for the float package version 1.3:

44 \wlog{rotfloat package: v1.3 of float detected}

\rotfloat@HH \rotfloat@restyle  \@HHfloat has changed to \float@HH here. Furthermore we need to redefine
\float@restyle instead of \restylefloat so \restylefloat* will still work.
45 \let\rotfloat@HH\@float@HH
46 \let\rotfloat@restyle\float@restyle
\@float@HH  \@Hxfloat has changed to \float@Hx here.
47 \def\@float@HH#1[H]{%
48  \rotfloat@xoftwo{\rotfloat@HH{#1}[H]}{\@float@Hx{#1}[!ht]}}
\float@restyle A \@float@setevery{#1} had to be added here.
49 \renewcommand*\float@restyle[1]{%
50  \rotfloat@restyle{#1}%
51  \@namedef{sideways#1}{%
52  \let\rotfloat@xoftwo\@secondoftwo\columnwidth\textheight
53  \@nameuse{fst@#1}\@float@setevery{#1}\@float{#1}}%
54  \expandafter\let\csname endsideways#1\endcsname\rotfloat@end
55  \ifx\@rotdblfloat\undefined
56  \@namedef{sideways#1*}{%
57  \PackageError{rotfloat}{%
58  You need rotating version 2.10 or newer to do this}{\@ehd}%
59  \@nameuse{sideways#1}}%
60  \expandafter\let\csname endsideways#1*\endcsname\rotfloat@end
61  \else
62  \@namedef{sideways#1*}{%
63  \let\rotfloat@xoftwo\@secondoftwo\columnwidth\textheight
64  \@nameuse{fst@#1}\@float@setevery{#1}\@dblfloat{#1}}%
65  \expandafter\let\csname endsideways#1*\endcsname\rotfloat@dblend
66  \fi}

\rotfloat@end \rotfloat@dblend Version 1.3 of float has a revised code of \float@end, mainly two things have changed here:

• \@endfloatbox is called to finish the current float instead of \egroup. Later on it is set to \relax so it don’t get called within \end@float again.

• \float@makebox has a parameter now, which will be set to \columnwidth or \textwidth. (In float 1.2 the \columnwidth was hard wired into

     \float@makebox.)

Note that the rotating package has is own code to handle the end of the float, so we call \@endfloatbox to finish the (empty) float, too, but we don’t need to copy the trick of setting \@endfloatbox to \relax and we don’t have to finish the \vbox ourself.

67 \newcommand*\rotfloat@end{\@endfloatbox
68  \global\setbox\@currbox\vbox\bgroup%
69  \def\@float##1[##2]{}\let\@xfloat\@float\@rotfloat{}%
70  \float@makebox\columnwidth\end@rotfloat}
71 \newcommand*\rotfloat@dblend{\@endfloatbox
72  \global\setbox\@currbox\vbox\bgroup%
73  \def\@float##1[##2]{}\let\@xfloat\@float\@rotdblfloat{}%
74  \float@makebox\textwidth\end@rotdblfloat}

That’s all folks.

75 \fi

References

[1] Anselm Lingnau: An Improved Environment for Floats, 1994/06/20

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