A style option for rotated objects in L^{A}TEX^{∗}

Leonor Barroca

1995/04/07

Contents

1 History 1

2 Usage 2

3 Setup 2

4 Turning and rotation environments 3

5 Sideways figures and tables 4 5.1 Rotated captions only . . . . . . . . . . . . . . . . . . . . . . . . . 5

List of Figures

List of Tables

Abstract

This article documents a L^{A}TEX package, ‘rotating.sty’, which perform all the different sorts of rotation one might like, including complete figures.

1 History

Version 2.0 is a complete re-write, with most of the work now being done by the L^{A}TEX 2ε graphics package.

Version 2.1 provides a ‘clockwise’ option to reinstate the behaviour described in the ‘L^{A}TEX Companion’

Version 2.2 just intercepts the standard float macros instead of copying and changing the. The ‘twoside’ option is obeyed.

Version 2.5 corrects problems in sideways figures.

Version 2.6 is a rewrite of the sideways floats via Frank Mittelbach (to whom many thanks for lookingat the mangy code).

Version 2.7 is checked for L^{A}TEX of December 94, and adds the option of twoside behaviour independent of the general twoside.

∗This file has version number 2.9, last revised 1995/04/07.

Version 2.8 cleans up some mistakes pointed out by Harald Axel Sommerfeldt. Version 2.9 cleans up some (more) mistakes pointed out by Harald Axel Sommerfeldt.

2 Usage

This style option provides three L^{A}TEX environments:

sideways prints the contents turned through 90 degrees counterclockwise

turn prints the contents turned through an arbitrary angle

rotate prints the contents turned through an arbitrary angle but does not leave any space for the result

A full set of examples are given in the file examples.tex Now we present the documented code.

3 Setup

1 ⟨∗package⟩

 2 \ProvidesPackage{rotating}[\filedate\space\fileversion\space Rotation package]
 3 \NeedsTeXFormat{LaTeX2e}
 4 \newif\if@rot@twoside
 5 \DeclareOption{clockwise}{% this is for compatibility
 6 \AtBeginDocument{\setkeys{Grot}{units=360}}%
 7 }
 8 \DeclareOption{counterclockwise}{%
 9 \AtBeginDocument{\setkeys{Grot}{units=-360}}%

10 }

Sideways figures and tables always take up the whole page. They can be rotated so that the bottom ot the figures is on the left or the right; the default is to always turn to the right. If the ‘twoside’ option has been given to the main document class, this package then starts rotating sideways figures according to the page number (this requires two passes through L^{A}TEX at least). If you want the ‘twoside’ option, but want the figures always in one direction, use the ‘figuresright’ or ‘riguresleft’ options to ‘rotating’.

11 \DeclareOption{figuresleft}{%
12 \@rot@twosidefalse
13 \def\rot@LR{0}%

14 }

15 \DeclareOption{figuresright}{%
16 \@rot@twosidefalse
17 \def\rot@LR{-1}%

18 }

19 \DeclareOption*{\PassOptionsToPackage{\CurrentOption}{graphics}}
20 \PassOptionsToPackage{dvips}{graphics}
21 \ExecuteOptions{clockwise}
22 \if@twoside
23 \@rot@twosidetrue
24 \else

25 \@rot@twosidefalse
26 \fi
27 \def\rot@LR{-1}
28 \ProcessOptions
29 \RequirePackage{graphicx}
30 \RequirePackage{ifthen}
31 \def\rotdriver#1{\makeatletter\input{#1.def}\makeatother}
32 \newcount\r@tfl@t
33 \r@tfl@t0

4 Turning and rotation environments

sideways Environment to turn the contents through 90 degrees.

34 \def\sideways{%
35 \Grot@setangle{90}%
36 \setbox\z@\hbox\bgroup\ignorespaces}
37 \def\endsideways{%
38 \unskip\egroup
39 \Grot@x\z@
40 \Grot@y\z@
41 \Grot@box

42 }

turn Rotate the contents of the environment, leaving the appropriate space

43 \def\turn#1{%
44 \Grot@setangle{#1}%
45 \setbox\z@\hbox\bgroup\ignorespaces}
46 \def\endturn{%
47 \unskip\egroup
48 \Grot@x\z@
49 \Grot@y\z@
50 \Grot@box

51 }

rotate Rotate the contents of the environment, leaving no space.

52 \def\rotate#1{%
53 \Grot@setangle{#1}%
54 \setbox\z@\hbox\bgroup\ignorespaces}
55 \def\endrotate{%
56 \unskip\egroup
57 \Grot@x\z@
58 \Grot@y\z@
59 \wd0\z@\dp0\z@\ht0\z@
60 \Grot@box

61 }

\turnbox A macro version of the ‘rotate’ environment.

62 \def\turnbox#1#2{%
63 \Grot@setangle{#1}%
64 \setbox\z@\hbox{{#2}}%
65 \Grot@x\z@\Grot@y\z@
66 \wd0\z@\dp0\z@\ht0\z@
67 \Grot@box

5 Sideways figures and tables

Now for the macros to provide a complete environment for sideways figures and tables. We define two environments sidewaysfigure and sidewaystable that fit in with the normal table and figure floats. These are ‘fixed’ environments that just do 90 degree rotation, but it would be easy to parameterize this to do other rotations if needed (the mind boggles…)

First a generalised ‘rotfloat’ environment. We need to intercept L^{A}TEX’s float macros, in order to change the assumed width of a float being \columnwidth. We want it to work on a width of \textheight so that when we rotate the float, it comes out the right height. This is not actually very satisfactory, since what we really want is for rotated floats to occupy the space they actually use. The captions are a problem — since they can precede the figure or table, we cannot set them in a box of the right width (ie the height of the forthcoming object), because it has not happened yet. The result of these difficulties is that rotated figures always end up as full page figures.

69 \newsavebox\rot@float@box
70 \def\@rotfloat#1{%
71 \@ifnextchar[%
72  {\@xrotfloat{#1}}%
73  {\edef\@tempa{\noexpand\@xrotfloat{#1}[\csname fps@#1\endcsname]}\@tempa}%

74 }

75 \def\@xrotfloat#1[#2]{%
76 \@float{#1}[#2]%

Set the float contents in a box of \textheight instead of \columnwidth.

77 \begin{lrbox}\rot@float@box
78 \begin{minipage}\textheight

79 }

We call the \end@float macro having previously rotated the box \@currbox The rotation is either clockwise or anti-clockwise, depending on whether the page is odd or even; in oneside mode it is always odd.

80 \def\end@rotfloat{%

If we are going to know whether pages are odd or even, we need to use the \pageref mechanism, and labels. But Labels won’t work unless the user has put in a caption. Beware!

81 \end{minipage}\end{lrbox}%
82 \global\advance\r@tfl@t by 1
83 \label{RF\the\r@tfl@t}%
84 \message{Adding sideways figure on }%
85 \def\R@@page{\pageref{RF\the\r@tfl@t}}%
86 \wd\rot@float@box\z@
87 \ht\rot@float@box\z@
88 \dp\rot@float@box\z@
89 \vbox to \textheight{%

We need to know for sure which direction rotation is going to be in, so locally reset the graphics units.

90  \setkeys{Grot}{units=360}%

 91  \if@rot@twoside
 92  \def\R@@page{\pageref{RF\the\r@tfl@t}}%
 93  \else
 94  \let\R@@page\rot@LR
 95  \fi
 96  \ifthenelse{\isodd{\R@@page}}{%
 97  \message{right hand page}%
 98  \vfill
 99  \centerline{\rotatebox{90}{\box\rot@float@box}}%
100  }{%
101  \message{left hand page}%
102  \centerline{\rotatebox{-90}{\box\rot@float@box}}%
103  \vfill

104 }% 105 }%

106 \end@float

107 }

The following definitions set up two environments, sidewaystable and sidewaysfigure, which uses this type of float. Naturally, users may need to change these to suit their local style. Both contribute to the normal lists of figures and tables.

108 \def\sidewaysfigure{\@rotfloat{figure}}

109 %

110 \let\endsidewaysfigure\end@rotfloat

111 %

112 \def\sidewaystable{\@rotfloat{table}}
113 \let\endsidewaystable\end@rotfloat

5.1 Rotated captions only

Sometimes you may find that the rotation of complete figures does not give quite the right result, since they always take up the whole page. You may prefer to rotate the caption and the float contents separately within a conventional figure. Here we offer a suggestion for a \rotcaption command, which inserts the caption rotated by 90 degrees. It is essentially a copy of the normal captioning code. Styles which define the \@makecaption command may also need to define \@makerotcaption.

114 \def\rotcaption{\refstepcounter\@captype\@dblarg{\@rotcaption\@captype}}
115 \long\def\@rotcaption#1[#2]#3{%
116 \addcontentsline{\csname ext@#1\endcsname}{#1}{%
117 \protect\numberline{\csname the#1\endcsname}{\ignorespaces #2}}%
118 \par
119 \begingroup
120  \@parboxrestore
121  \normalsize
122  \@makerotcaption{\csname fnum@#1\endcsname}{#3}%
123 \endgroup}
124 \long\def\@makerotcaption#1#2{%
125 \setbox\@tempboxa\hbox{#1: #2}%
126 \ifdim \wd\@tempboxa > .8\vsize
127  \rotatebox{90}{%
128  \begin{minipage}{.8\textheight}#1: #2\end{minipage}%
129  }\par
130 \else%

131  \rotatebox{90}{\box\@tempboxa}%
132 \fi
133 \hspace{12pt}%

134 }

¡/package¿