The sidecap package

Rolf Niepraschk

niepraschk@ptb.de (INTERNET)

v1.00 – 1997/05/08

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 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 requires at least two compilation runs.

2 Usage

\usepackage[⟨option⟩]{sidecap}
...
\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., 100) 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

 3 \typeout{Package: SideCap v1.00 <1997/05/08> (RN)}

4

 5 \RequirePackage{ifthen}

6

 7 \newlength{\SCtab@figLEN} \newlength{\SCcap@LEN}
 8 \newcounter{SC@figureC} \newcounter{SC@tableC}
 9 \newsavebox{\SCtab@figBOX} \newcommand\SCtab@fig{}

10

11 \newcommand\SC@LABEL{SC@\@captype:\number\value{SC@\@captype C}}

12

\SCtab@fig 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 figure or table inside.

13 \DeclareOption{innercaption}{%
14 \renewcommand\SCtab@fig[3]{\ifthenelse{\isodd{\pageref{#1}}}
15  {{#2}\hspace{\columnsep}{#3}} {{#3}\hspace{\columnsep}{#2}}}}

16

17 \DeclareOption{outercaption}{%
18 \renewcommand\SCtab@fig[3]{\ifthenelse{\isodd{\pageref{#1}}}
19  {{#3}\hspace{\columnsep}{#2}} {{#2}\hspace{\columnsep}{#3}}}}

20

21 \DeclareOption{rightcaption}{%
22 \renewcommand\SCtab@fig[3]{{#3}\hspace{\columnsep}{#2}}}

23

24 \DeclareOption{leftcaption}{%
25 \renewcommand\SCtab@fig[3]{{#2}\hspace{\columnsep}{#3}}}

26

27 \ExecuteOptions{outercaption} \ProcessOptions

28

\SCfigure Checks the two optional parameters and jumps to SC@float with parameter ‘figure’.

29 \def\SCfigure{\@ifnextchar[%
30 \SC@figure {\SC@@figure{1.0}[\fps@figure]}}
31 \def\SC@figure[#1]{\@ifnextchar[%
32 {\SC@@figure{#1}} {\SC@@figure{1.0}[#1]}}
33 \def\SC@@figure#1[#2]{\SC@float{#1}{figure}{#2}}
\endSCfigure
34 \def\endSCfigure{\endSC@float}

35

\SCtable Checks the two optional parameters and jumps to SC@float with parameter ‘table’.

36 \def\SCtable{\@ifnextchar[%
37 \SC@table {\SC@@table{1.0}[\fps@table]}}
38 \def\SC@table[#1]{\@ifnextchar[%

39 {\SC@@table{#1}} {\SC@@table{1.0}[#1]}}
40 \def\SC@@table#1[#2]{\SC@float{#1}{table}{#2}}
\endSCtable
41 \def\endSCtable{\endSC@float}

42

\SC@float The new float environment. Parameter 1 is relwidth, Parameter 2 is ‘figure’ or ‘table’, Parameter 3 is the floating position.

43 \def\SC@float#1#2#3{%
44 \expandafter\edef\csname fps@#2\endcsname{#3}%
45 \gdef\@captype{#2}\def\SC@fraction{#1}%

The caption and label commands must be safed and redefined.

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

Save the figure or table in a box.

51 \begin{lrbox}{\SCtab@figBOX}%
52 }%

53

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

54 \def\endSC@float{%
55 \end{lrbox}%

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.

56 \settowidth\SCtab@figLEN{\usebox\SCtab@figBOX}%
57 \setlength\SCcap@LEN{\SC@fraction\SCtab@figLEN}%
58 \setlength\@tempdima{\SCtab@figLEN}%
59 \addtolength\@tempdima{\SCcap@LEN}%
60 \addtolength\@tempdima{\columnsep}%
61 \ifthenelse{\lengthtest{\@tempdima>\linewidth}}%
62  {\addtolength\SCcap@LEN{-\@tempdima}%
63  \addtolength\SCcap@LEN{\linewidth}}{}%

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

64 \@float{\@captype}%
65  \setlength\abovecaptionskip{0pt}%
66  \setlength\belowcaptionskip{0pt}%

Creates a label for each figure or table for later determination if the page is odd or even. The counters SC@figureC or SC@tableC must be incremented before.

67  \stepcounter{SC@\@captype C}\SC@SAVlabel{\SC@LABEL}%
68  \begin{minipage}[b]{\linewidth}%
69  \centering%

The figure caption should be bottom aligned, the table caption top aligned.

70  \ifthenelse{\equal{\@captype}{figure}}{\def\SC@pos{b}}{\def\SC@pos{t}}%
71  \SCtab@fig{\SC@LABEL}%
72  {\begin{minipage}[\SC@pos]{\SCcap@LEN}%
73  \ifthenelse{\equal{\SC@OPTCAPtext}{\@empty}}%

74  {\SC@SAVcaption{\expandafter\protect\SC@CAPtext}}%
75  {\SC@SAVcaption[\expandafter\protect\SC@OPTCAPtext]%
76  {\expandafter\protect\SC@CAPtext}}%
77  \ifthenelse{\equal{\SC@LABtext}{\@empty}}%
78  {}{\SC@SAVlabel{\expandafter\protect\SC@LABtext}}%
79  \end{minipage}}%
80  {\begin{minipage}[\SC@pos]{\SCtab@figLEN}%
81  \rule{\linewidth}{0pt} %
82  \usebox{\SCtab@figBOX}%
83  \end{minipage}}%
84  \end{minipage}%
85 \end@float%

86 }

87 ⟨/package⟩