summaryrefslogtreecommitdiff
path: root/usergrps/uktug/baskervi/3_2/bailey.tex
blob: af7566f7f1935f9a4a95fc0849bbae6f2e9d9bf1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
\newtheorem{prequestion}{Question}
\newtheorem{preanswer}{Answer}
\renewcommand{\thepreanswer}{}
\newenvironment{question}{\begin{prequestion}\rm}{\end{prequestion}}
\newenvironment{answer}{\begin{preanswer}\rm}{\end{preanswer}}
\newcommand{\latexword}[1]{{\rm\tt #1}}
\newcommand{\lamport}{{\it \LaTeX: A Document Preparation System\/} by Leslie 
Lamport}
\newcommand{\shortlamp}{{\it The Manual}}

\author[R.~A.~Bailey]{R.~A.~Bailey\\Goldsmiths' College, University of London}
\title{Topical Tips --- side by side figures in \LaTeX}

\begin{article}

\setlength{\unitlength}{0.1cm}
\newcommand{\blob}{\circle*{3}}

\begin{question}
How do I set two figures side by side in \LaTeX?
\end{question}

\begin{answer}
I assume that you mean how do you set a pair of figures
something like Figures~\ref{anova} and~\ref{hasse} below.


\begin{figure}[htbp]
\noindent
\makebox[\columnwidth]{%
\begin{minipage}[b]{0.5\columnwidth}
\[
\begin{array}{lc}
\mbox{Source} & \mbox{df}\\
\hline
\mbox{blocks} & b-1\\
\mbox{varieties} & k-1\\
\mbox{residual} & (b-1)(k-1)\\
\hline
\mbox{total} & bk-1
\end{array}
\]
\caption{The analysis-of-variance table\strut}
\label{anova}
\end{minipage}%
\hfill
\begin{minipage}[b]{0.4\columnwidth}
\begin{center}
\begin{picture}(20,25)(-10,-2)
\put(0,0){\line(0,1){20}}
\put(0,0){\blob}
\put(0,10){\blob}
\put(0,20){\blob}
\put(0,-4){\makebox(0,0)[t]{$bk$ plots}}
\put(0,24){\makebox(0,0)[b]{$1$ universe}}
\put(2,10){\makebox(0,0)[l]{$b$ blocks}}
\end{picture}
\end{center}
\caption{The Hasse diagram\strut}
\label{hasse}
\end{minipage}%
}
\end{figure}

That pair of figures consists of two objects in a single \latexword{figure} 
environment (more on that later).
Here is how I did them.
{\fontseries{n}\selectfont\begin{verbatim}
\begin{figure}
  \noindent
  \makebox[\textwidth]{%
  \begin{minipage}[b]{0.5\textwidth}
  <first object>
  <first caption>
  \end{minipage}%
  \hfill
  \begin{minipage}[b]{0.4\textwidth}
  <second object>
  <second caption>
  \end{minipage}%
  }
  \end{figure}
\end{verbatim}
}
\end{answer}
(Well, what I've just said isn't totally true, but I'll come back to
that.) The first object is an \latexword{array} inside displayed
maths, while the second object is a \latexword{picture}. The objects
can be anything you like, including tables and straight text.
Figures~\ref{box} and~\ref{alice} are done similarly.

In both cases I've put each object in a \latexword{minipage}: see
pages 98--99 of \lamport, hereafter called \shortlamp. The
\latexword{minipage} takes an argument specifying its width. Rather
than defining the widths of the objects absolutely, I prefer to define
them in terms of \verb+\+\latexword{textwidth}, which is described on
page~94 of \shortlamp. I've chosen two fractions which seem to me in
the right proportion and which add up to less than~1: in
Figures~\ref{box} and~\ref{alice} the proportions are $0.3$ and $0.6$.

Normally, \latexword{minipage}s are horizontally aligned around a
central horizontal axis. I prefer to have the two \latexword{caption}s
lined up nicely, so I have given both the \latexword{minipage}s the
optional argument \latexword{b}, which aligns them at the bottom.

The two \latexword{minipage}s are put inside a box which is just as
wide as the text. This is made with \verb+\+\latexword{makebox} (see
page~97 of \shortlamp\/), whose optional argument specifies the width
of the box. There is a \verb+\+\latexword{noindent} before it, to make
sure that there is no space on the left before the box starts. The
\latexword{\%} sign immediately after the start of the box lets me
start a new line in the input file without introducing a space before
the first \latexword{minipage}: in other words, the first
\latexword{minipage} is flush left to the edge of the text. In the
same way, the \latexword{\%} sign after each
\verb+\+\latexword{end}\verb+{+\latexword{minipage}\verb+}+ prevents a
little inter-word space creeping in after each \latexword{minipage}.
This fussiness is not evident in Figures~\ref{anova} and~\ref{hasse},
but does show up in Figures~\ref{box} and~\ref{alice}, which have
visible outer edges flush with the edges of the surrounding text.

Finally, \verb+\+\latexword{hfill} is put in between the 
two \latexword{minipage}s, 
forcing them as far apart as they will go: see page~96 of \shortlamp.

\begin{figure}[hbp]
\noindent
\makebox[\columnwidth]{%
\begin{minipage}[b]{0.3\columnwidth}
\begin{picture}(30,30)
\put(0,0){\framebox(20,10){E}}
\put(0,10){\framebox(10,10){C}}
\put(10,10){\framebox(10,10){D}}
\put(0,20){\framebox(10,10){A}}
\put(10,20){\framebox(10,10){B}}
\end{picture}
\caption{Five objects in one figure}
\label{box}
\end{minipage}%
\hfill
\begin{minipage}[b]{0.6\columnwidth}
\begin{flushright}
Tomorrow, and tomorrow, and tomorrow,
 creeps in this petty pace from day to day, to 
the last syllable of recorded time; and all our yesterdays have lighted fools 
the way to dusty death.
\end{flushright}
\caption{Philosophy}
\label{alice}
\end{minipage}%
}
\end{figure}

I expect that you asked this question because of a misunderstanding
about what a \LaTeX\ \latexword{figure} is. It is not really a figure
at all: it is what \shortlamp\/ calls a {\em float}. That is, it is a
chunk of text---or maths, or pictures, or whatever---that is treated
as a whole and is printed in the first convenient place where there is
room for it. It may contain any number of \latexword{caption}s (even
none), each of which produces output beginning ``Figure \ldots''. I
have used the word ``object'' for what you probably think of as a
figure. You have to visually place the objects and captions within the
\latexword{figure} so that the captions refer to the correct objects.

If you do not want to force the two objects to the edges of the text, you can 
omit the \latexword{makebox} and put explicit space between the two 
\latexword{minipage}s, something like
\begin{verbatim}
  \begin{figure}
  \centering 
  \begin{minipage}[b]{0.5\textwidth}
  <first object>
  <first caption>
  \end{minipage}%
  \hspace{1cm}
  \begin{minipage}[b]{0.4\textwidth}
  <second object>
  <second caption>
  \end{minipage}%
  \end{figure}
\end{verbatim}

You can also stack two \latexword{minipage}s on top of each other in a single 
\latexword{figure}. If their total width is more than 
\verb+\+\latexword{textwidth} you do not even have to force them onto two 
separate lines. In this way you can glue five objects together in one figure in
the arrangement shown in Figure~\ref{box}.

Now to the lies. Since \BV\ is set in two columns, all the figures
in this article have been done using \verb+\+\latexword{columnwidth}
instead of \verb+\+\latexword{textwidth}. If you do the captions as I
have suggested, then that for Figure~\ref{anova} appears to come out a
little lower than that for Figure~\ref{hasse}. This is because the
second \latexword{caption} contains the descending letter `g' whereas
`variance table' contains no descenders. So the bottom of the `g' is
lined up with the baseline of the first caption. To cure this, we can
put in the useful command \verb+\+\latexword{strut}, which isn't in
\shortlamp. It produces no visible output, and has height but no
width. The principle is explained on page~100 of \shortlamp. The
command \verb+\+\latexword{strut} produces a strut whose size depends
on the current font size. It is big enough to cover the descenders and
ascenders on ordinary letters. Two lines of ordinary text that both
contain \verb+\+\latexword{strut} both take up the same amount of
vertical space.  So we finish the first and second captions with
\begin{verbatim}
  table\strut}
\end{verbatim}
and
\begin{verbatim}
  diagram\strut}
\end{verbatim}
being careful not to introduce an extra inter-word space before the strut.

Any statistician reading this will probably object that
Figure~\ref{anova} should be called a {\em table}. Here's the rub. I
can put any number of \latexword{caption}s inside a \latexword{figure}
and they will all come out ``Figure \ldots''. Similarly, I can put
several \latexword{caption}s inside a \latexword{table} and they will
all come out ``Table \ldots''. What I cannot do is mix ``Table''s and
``Figure''s in the same \LaTeX\ float. In particular, I cannot put a
``Table'' beside a ``Figure''. Nor can the average \LaTeX\ user. Let
us hope that the \LaTeX3 team will give us this flexibility.

\end{article}