The sidecap package

                Rolf Niepraschk (niepraschk@ptb.de)
                Hubert Gäßlein (gaesslein@bned.com)

v1.4d – 1999/05/11

Abstract This package defines the new environments SCfigure and SCtable, analogous to figure and table, which make it easy to typeset captions sideways.

1 Introduction

In some cases it may be useful to typeset the caption aside the figure or the table. For this purpose the package sidecap defines the new environments SCfigure and SCtable. The figure or the table and the caption are put into two minipages that are positioned side by side and centered as a whole. The space between the minipages is \columnsep. The correct positioning with respect to left and right pages requires at least two compilation runs.

2 Usage

\usepackage[⟨option⟩]{sidecap}
\begin{SCtable}  [⟨relwidth⟩][⟨float⟩] ...  \end{SCtable}
\begin{SCfigure} [⟨relwidth⟩][⟨float⟩] ...  \end{SCfigure}
\begin{SCtable*} [⟨relwidth⟩][⟨float⟩] ...  \end{SCtable*}
\begin{SCfigure*}[⟨relwidth⟩][⟨float⟩] ...  \end{SCfigure*}

⟨option⟩ – outercaption (default): caption appears left on left pages and right on right pages. innercaption: caption appears right on left pages and left on right pages. leftcaption: caption is always on the left. rightcaption: caption is always on the right. ⟨relwidth⟩ – optional; caption width relative to the width of the figure or

table. A large value (e.g., 50) reserves the maximum width that is possible. Default is 1.0 .

⟨float⟩ – optional; like the floating position parameter of the original table/figure environments. Default is tbp.

3 Required packages

The package requires the standard L^{A}TEX package ifthen.

4 THE IMPLEMENTATION 2

4 The implementation

1 ⟨∗package⟩

 2 \typeout{Package: SideCap v1.4d <1999/05/11> (RN/HjG)}

3

 4 \RequirePackage{ifthen}

5

 6 \newlength{\SC@BOXWD} \newlength{\SC@CAPWD}
 7 \newcounter{SC@C}
 8 \newsavebox{\SC@BOX} \newcommand\SC@FLOAT{}

9

10 \newcommand\SC@LABEL{SC@LABEL:\number\value{SC@C}}

11

\SC@FLOAT Has three parameters. The first is the label that determines if the current page is odd or even. This parameter is only used with the options outercaption or innercaption. The second parameter is the minipage with the caption text inside and the last parameter is the minipage with the body of the figure or table inside.

12 \DeclareOption{innercaption}{%
13 \renewcommand\SC@FLOAT[3]{\ifthenelse{\isodd{\pageref{#1}}}
14  {{#2}\hspace{\columnsep}{#3}} {{#3}\hspace{\columnsep}{#2}}}}

15

16 \DeclareOption{outercaption}{%
17 \renewcommand\SC@FLOAT[3]{\ifthenelse{\isodd{\pageref{#1}}}
18  {{#3}\hspace{\columnsep}{#2}} {{#2}\hspace{\columnsep}{#3}}}}

19

20 \DeclareOption{rightcaption}{%
21 \renewcommand\SC@FLOAT[3]{{#3}\hspace{\columnsep}{#2}}}

22

23 \DeclareOption{leftcaption}{%
24 \renewcommand\SC@FLOAT[3]{{#2}\hspace{\columnsep}{#3}}}

25

26 \ExecuteOptions{outercaption} \ProcessOptions

27

SCfigure Simply passes the first (optional) parameter and the required one, in this case ‘figure’, to SC@float . The figure caption should be bottom aligned.

28

29 \newenvironment{SCfigure}{\SC@float[b]{figure}}{\endSC@float}
30 \newenvironment{SCfigure*}{\SC@dblfloat[b]{figure}}{\endSC@dblfloat}

31

SCtable Simply passes the first (optional) parameter and the required one, in this case ‘table’, to SC@float . The table caption should be top aligned.

32

33 \newenvironment{SCtable}{\SC@float[t]{table}}{\endSC@float}
34 \newenvironment{SCtable*}{\SC@dblfloat[t]{table}}{\endSC@dblfloat}

35

\SC@float The new float environment, similar/analogous to L^{A}TEX’s @float environment. Syntax: \SC@float[⟨vpos⟩]{⟨name⟩}[⟨relwd⟩][⟨fps⟩] Parameter 1 (optional) is the vertical positioning of the caption. Parameter 2 (required) is the name of the ‘original’ L^{A}TEX floating environment (e.g., ‘figure’ or ‘table’). Parameter 3 (optional) is the desired relative width of the caption. Parameter 4 (optional) is the usual L^{A}TEX float positioning specifier. The usual ‘cascading’ programming style is applied (cf. L^{A}TEX’s \@float). Initially, the first optional parameter is checked for.

36 \def\SC@float{\@ifnextchar[\SC@xfloat{\SC@xfloat[c]}}

Then the first and second parameters are consumed and the third one is checked for.

37 \def\SC@xfloat[#1]#2{\@ifnextchar[%
38 {\SC@yfloat{#1}{#2}}%
39 {\SC@zfloat{#1}{#2}{1.0}[\@nameuse{fps@#2}]}}

Again, the fourth (and last) parameter is checked for.

40 \def\SC@yfloat#1#2[#3]{\@ifnextchar[%
41 {\SC@zfloat{#1}{#2}{#3}}%
42 {\SC@zfloat{#1}{#2}{#3}[\@nameuse{fps@#2}]}}

Finally, here is the macro that does all the work.

43 \def\SC@zfloat#1#2#3[#4]{%
44 \def\SC@pos{#1}%
45 \expandafter\edef\csname fps@#2\endcsname{#4}%
46 \def\SC@captype{#2}%
47 \ifx#3\@empty\def\SC@fraction{1}\else\def\SC@fraction{#3}\fi%

The \caption and \label commands must be saved and redefined.

48 \let\SC@caption\caption \let\SC@label\label%
49 \let\SC@CAPtext\@empty \let\SC@OPTCAPtext\@empty \let\SC@LABtext\@empty%
50 \renewcommand\caption[2][]{\gdef\SC@OPTCAPtext{##1}\gdef\SC@CAPtext{##2}}%
51 \renewcommand\label[1]{\gdef\SC@LABtext{##1}}%
52 \@namedef{fnum@#2}{\mbox{\@nameuse{#2name}~\@nameuse{the#2}}}%

Save the figure or table (or whatever) in a box.

53 \begin{lrbox}{\SC@BOX}%
54 }%

55

\SC@dblfloat Analogous to L^{A}TEX’s \@dblfloat.
56 \def\SC@dblfloat{%
57 \if@twocolumn\let\reserved@a\SC@dbflt\else\let\reserved@a\SC@float\fi
58 \reserved@a}
59 \def\SC@dbflt{%
60 \SC@float}

\endSC@float Outputs the figure or table (or whatever) and the caption.

61 \def\endSC@float{%
62 \end{lrbox}%
63 ⟨+debug⟩ \typeout{onecolumn}%
64  \def\@FLOAT{\@float}\def\end@FLOAT{\end@float}\endSC@FLOAT{\columnwidth}}%
65 \def\endSC@dblfloat{%
66 \end{lrbox}%
67 ⟨+debug⟩ \typeout{twocolumn}%
68  \def\@FLOAT{\@dblfloat}\def\end@FLOAT{\end@dblfloat}\endSC@FLOAT{\textwidth}}%

Sets the caption width. If caption width plus figure/table width is too large then the caption width is set equal to the remaining width.

69 \def\endSC@FLOAT#1{%
70 \settowidth\SC@BOXWD{\usebox\SC@BOX}%
71 \setlength\SC@CAPWD{\SC@fraction\SC@BOXWD}%
72 \setlength\@tempdima{\SC@BOXWD}%
73 \addtolength\@tempdima{\SC@CAPWD}%
74 \addtolength\@tempdima{\columnsep}%
75 \ifthenelse{\lengthtest{\@tempdima>#1}}%
76  {\addtolength\SC@CAPWD{-\@tempdima}%
77  \addtolength\SC@CAPWD{#1}}{}%

Calls the L^{A}TEX float command with the two minipages inside a main minipage.

78 \@FLOAT{\SC@captype}%
79  \abovecaptionskip\z@skip
80  \belowcaptionskip\z@skip

Creates a label for each figure or table (etc.) for later determination if the page is odd or even. The counter SC@C must be incremented before.

81  \stepcounter{SC@C}\SC@label{\SC@LABEL}%
82  \begin{minipage}[b]{#1}%
83  \centering%
84  \SC@FLOAT{\SC@LABEL}%
85  {\begin{minipage}[\SC@pos]{\SC@CAPWD}%
86  \ifthenelse{\equal{\SC@OPTCAPtext}{\@empty}}%
87  {\SC@caption{\expandafter\protect\SC@CAPtext}}%
88  {\SC@caption[\expandafter\protect\SC@OPTCAPtext]%
89  {\expandafter\protect\SC@CAPtext}}%
90  \unskip%
91  \ifthenelse{\equal{\SC@LABtext}{\@empty}}%
92  {}{\SC@label{\expandafter\protect\SC@LABtext}}%
93  \end{minipage}}%
94  {\begin{minipage}[\SC@pos]{\SC@BOXWD}%
95  \offinterlineskip%
96  \kern0pt\relax
97  \usebox{\SC@BOX}%
98  \end{minipage}}%
99  \end{minipage}%
100 \end@FLOAT%

101 } 102 ⟨/package⟩