Debian Codegraph @

texmf-dist/doc/latex/bchart/bchart.tex

raw
1 \documentclass{article}
2
3 \usepackage{bchart}
4
5 \frenchspacing
6
7 \title{
8 \texttt{bchart}: Simple Bar Charts in \LaTeX
9 \medskip\\
10 \large Version 0.1.2
11 }
12 \author{Tobias Kuhn}
13 \date{22 August 2012}
14
15 \begin{document}
16
17 \maketitle
18
19
20 \section{Introduction}
21
22 \texttt{bchart} is a {\LaTeX} package for drawing simple bar charts with horizontal bars on a numerical x-axis. It is based on the TikZ drawing package. The focus of this package is on simplicity and aesthetics.
23
24 To use the package, you have to make sure that {\LaTeX} is able find the file \texttt{bchart.sty}, e.g. by placing a copy of it into the directory of the source file that is using the package. In order to load the package, you have to place the following command at the beginning of your {\LaTeX} source file:
25 \begin{quote}\small
26 \begin{verbatim}
27 \usepackage{bchart}
28 \end{verbatim}
29 \end{quote}
30
31
32 \section{Charts}
33
34 Charts are created with the \texttt{bchart}-environment. Within this environment, you can put one or more bars by using the \texttt{bcbar}-command. The code of a very simple chart and the resulting picture are shown here:
35 \begin{quote}\small
36 \begin{verbatim}
37 \begin{bchart}[max=50]
38 \bcbar{45}
39 \bcbar{26}
40 \bcbar{31}
41 \end{bchart}
42 \end{verbatim}
43 \end{quote}
44 \begin{quote}
45 \begin{bchart}[max=50]
46 \bcbar{45}
47 \bcbar{26}
48 \bcbar{31}
49 \end{bchart}
50 \end{quote}
51 The option \texttt{max} defines the maximum value on the x-axis (the default is 100). The number given to the \texttt{bcbar}-command defines the value of the respective bar, visualized by the width of the bar and printed as a number to the right of it. The minimum value on the x-axis defaults to 0, but this can be changed by the use of the option \texttt{min}. Furthermore, the option \texttt{step} can be used to show marks at regular intervals:
52 \begin{quote}\small
53 \begin{verbatim}
54 \begin{bchart}[min=2.5,step=0.25,max=3.75]
55 \bcbar{2.6}
56 \bcbar{3.7}
57 \bcbar{3.1}
58 \end{bchart}
59 \end{verbatim}
60 \end{quote}
61 \begin{quote}
62 \begin{bchart}[min=2.5,step=0.25,max=3.75]
63 \bcbar{2.6}
64 \bcbar{3.7}
65 \bcbar{3.1}
66 \end{bchart}
67 \end{quote}
68 For marks at irregular intervals, the \texttt{steps}-option can be used instead:
69 \begin{quote}\small
70 \begin{verbatim}
71 \begin{bchart}[min=1,max=18,steps={1,3,7,15}]
72 \bcbar{13}
73 \bcbar{4}
74 \bcbar{7}
75 \end{bchart}
76 \end{verbatim}
77 \end{quote}
78 \begin{quote}
79 \begin{bchart}[min=1,max=18,steps={1,3,7,15}]
80 \bcbar{13}
81 \bcbar{4}
82 \bcbar{7}
83 \end{bchart}
84 \end{quote}
85 The \texttt{plain}-flag hides all marks:
86 \begin{quote}\small
87 \begin{verbatim}
88 \begin{bchart}[max=8,plain]
89 \bcbar{6.2}
90 \bcbar{1.8}
91 \end{bchart}
92 \end{verbatim}
93 \end{quote}
94 \begin{quote}
95 \begin{bchart}[max=8,plain]
96 \bcbar{6.2}
97 \bcbar{1.8}
98 \end{bchart}
99 \end{quote}
100 The font style is sans-serif by default. This can be changed by redefining the command \texttt{bcfontstyle}:
101 \begin{quote}\small
102 \begin{verbatim}
103 \renewcommand{\bcfontstyle}{\bfseries}
104 \begin{bchart}[max=10,step=1]
105 \bcbar{5.7}
106 \end{bchart}
107 \end{verbatim}
108 \end{quote}
109 \begin{quote}
110 \renewcommand{\bcfontstyle}{\bfseries}
111 \begin{bchart}[max=10,step=1]
112 \bcbar{5.7}
113 \end{bchart}
114 \end{quote}
115 With an empty argument, the default font of the document is used:
116 \begin{quote}\small
117 \begin{verbatim}
118 \renewcommand{\bcfontstyle}{}
119 \begin{bchart}[max=10,step=1]
120 \bcbar{5.7}
121 \end{bchart}
122 \end{verbatim}
123 \end{quote}
124 \begin{quote}
125 \renewcommand{\bcfontstyle}{}
126 \begin{bchart}[max=10,step=1]
127 \bcbar{5.7}
128 \end{bchart}
129 \end{quote}
130
131
132 \section{Bars}
133
134 The bars of a bar chart can be modified in several ways. The \texttt{text}-option prints text within the inside of the bar:
135 \begin{quote}\small
136 \begin{verbatim}
137 \begin{bchart}[step=2,max=8]
138 \bcbar[text=Year 1]{6}
139 \bcbar[text=Year 2]{3}
140 \end{bchart}
141 \end{verbatim}
142 \end{quote}
143 \begin{quote}
144 \begin{bchart}[step=2,max=8]
145 \bcbar[text=Year 1]{6}
146 \bcbar[text=Year 2]{3}
147 \end{bchart}
148 \end{quote}
149
150 The bars can be given different background colors by the use of the \texttt{color}-option:
151 \begin{quote}\small
152 \begin{verbatim}
153 \begin{bchart}[max=8]
154 \bcbar[text=A,color=yellow]{6}
155 \bcbar[text=B,color=red!50]{3}
156 \bcbar[text=C,color=green!60!blue]{4}
157 \end{bchart}
158 \end{verbatim}
159 \end{quote}
160 \begin{quote}
161 \begin{bchart}[max=8]
162 \bcbar[text=A,color=yellow]{6}
163 \bcbar[text=B,color=red!50]{3}
164 \bcbar[text=C,color=green!60!blue]{4}
165 \end{bchart}
166 \end{quote}
167 In addition to predefined colors like \texttt{yellow} and \texttt{red}, new colors can be defined and existing ones can be combined. \texttt{red!50}, for example, stands for a 50\% saturated red, whereas \texttt{green!60!blue} stands for a color obtained by blending green and blue at a ratio of 60:40. See the TikZ manual for more information on how to manipulate colors. The default color for bars is \texttt{blue:20}.
168
169 The \texttt{plain}-flag can be used to prevent the value of the bar to be displayed:
170 \begin{quote}\small
171 \begin{verbatim}
172 \begin{bchart}[step=1,max=8]
173 \bcbar[plain]{6}
174 \bcbar[plain]{3}
175 \end{bchart}
176 \end{verbatim}
177 \end{quote}
178 \begin{quote}
179 \begin{bchart}[step=1,max=8]
180 \bcbar[plain]{6}
181 \bcbar[plain]{3}
182 \end{bchart}
183 \end{quote}
184
185 With the \texttt{value}-option, the value to be displayed to the right of the bar can be modified:
186 \begin{quote}\small
187 \begin{verbatim}
188 \begin{bchart}[step=2,max=8]
189 \bcbar[value=six]{6}
190 \bcbar[value=III]{3}
191 \end{bchart}
192 \end{verbatim}
193 \end{quote}
194 \begin{quote}
195 \begin{bchart}[step=2,max=8]
196 \bcbar[value=six]{6}
197 \bcbar[value=III]{3}
198 \end{bchart}
199 \end{quote}
200
201
202 \section{Skips}
203
204 The common commands \texttt{smallskip}, \texttt{medskip} and \texttt{bigskip} are redefined within the bar chart environment and can be used to insert skips of different sizes between two bars:
205 \begin{quote}\small
206 \begin{verbatim}
207 \begin{bchart}[step=2,max=10]
208 \bcbar{3.4}
209 \smallskip
210 \bcbar{5.6}
211 \medskip
212 \bcbar{7.2}
213 \bigskip
214 \bcbar{9.9}
215 \end{bchart}
216 \end{verbatim}
217 \end{quote}
218 \begin{quote}
219 \begin{bchart}[step=2,max=10]
220 \bcbar{3.4}
221 \smallskip
222 \bcbar{5.6}
223 \medskip
224 \bcbar{7.2}
225 \bigskip
226 \bcbar{9.9}
227 \end{bchart}
228 \end{quote}
229 With the \texttt{bcskip}-command, skips of arbitrary size can be inserted:
230 \begin{quote}\small
231 \begin{verbatim}
232 \begin{bchart}[step=10,max=100]
233 \bcbar{83}
234 \bcskip{3pt}
235 \bcbar{25}
236 \bcskip{15mm}
237 \bcbar{69}
238 \end{bchart}
239 \end{verbatim}
240 \end{quote}
241 \begin{quote}
242 \begin{bchart}[step=10,max=100]
243 \bcbar{83}
244 \bcskip{3pt}
245 \bcbar{25}
246 \bcskip{15mm}
247 \bcbar{69}
248 \end{bchart}
249 \end{quote}
250
251
252 \section{Labels}
253
254 The x-axis can be labeled by calling the \texttt{bcxlabel}-command:
255 \begin{quote}\small
256 \begin{verbatim}
257 \begin{bchart}[step=200,max=1000]
258 \bcbar[text=Company A]{346}
259 \bcbar[text=Company B]{873}
260 \bcxlabel{number of employees}
261 \end{bchart}
262 \end{verbatim}
263 \end{quote}
264 \begin{quote}
265 \begin{bchart}[step=200,max=1000]
266 \bcbar[text=Company A]{346}
267 \bcbar[text=Company B]{873}
268 \bcxlabel{number of employees}
269 \end{bchart}
270 \end{quote}
271 The option \texttt{label} can be used to label bars and skips:
272 \begin{quote}\small
273 \begin{verbatim}
274 \begin{bchart}[step=2,max=16]
275 \bcbar[label=1st bar]{8.5}
276 \bigskip[label=skip]
277 \bcbar[label=2nd bar]{4.5}
278 \end{bchart}
279 \end{verbatim}
280 \end{quote}
281 \begin{quote}
282 \begin{bchart}[step=2,max=16]
283 \bcbar[label=1st bar]{8.5}
284 \bigskip[label=skip]
285 \bcbar[label=2nd bar]{4.5}
286 \end{bchart}
287 \end{quote}
288 The command \texttt{bclabel} generates ``free'' labels at the respective position in the chart:
289 \begin{quote}\small
290 \begin{verbatim}
291 \begin{bchart}[step=2,max=16]
292 \bcbar{8.5}
293 \bclabel{free label}
294 \bcbar{4.5}
295 \end{bchart}
296 \end{verbatim}
297 \end{quote}
298 \begin{quote}
299 \begin{bchart}[step=2,max=16]
300 \bcbar{8.5}
301 \bclabel{free label}
302 \bcbar{4.5}
303 \end{bchart}
304 \end{quote}
305
306
307 \section{Units}
308
309 The \texttt{unit}-option of the chart environment attaches a unit to all values, like ``kg'', ``m\textsuperscript{2}'', or ``\%'':
310 \begin{quote}\small
311 \begin{verbatim}
312 \begin{bchart}[min=50,max=100,step=10,unit=\%]
313 \bcbar{72.3}
314 \end{bchart}
315 \end{verbatim}
316 \end{quote}
317 \begin{quote}
318 \begin{bchart}[min=50,max=100,step=10,unit=\%]
319 \bcbar{72.3}
320 \end{bchart}
321 \end{quote}
322 \begin{quote}\small
323 \begin{verbatim}
324 \begin{bchart}[min=50,max=100,step=10,unit=m\textsuperscript{2}]
325 \bcbar{72.3}
326 \end{bchart}
327 \end{verbatim}
328 \end{quote}
329 \begin{quote}
330 \begin{bchart}[min=50,max=100,step=10,unit=m\textsuperscript{2}]
331 \bcbar{72.3}
332 \end{bchart}
333 \end{quote}
334
335
336 \section{Width and Scaling}
337
338 The \texttt{width}-option of the chart environment allows for adjusting the width of the chart:
339 \begin{quote}\small
340 \begin{verbatim}
341 \begin{bchart}[max=10,step=2,width=4cm]
342 \bcbar{7.5}
343 \bcbar{3.2}
344 \end{bchart}
345 \end{verbatim}
346 \end{quote}
347 \begin{quote}
348 \begin{bchart}[max=10,step=2,width=4cm]
349 \bcbar{7.5}
350 \bcbar{3.2}
351 \end{bchart}
352 \end{quote}
353 Note that the height of the chart is not affected by this, nor is the size or shape of the text. The default width is 8cm.
354
355 In order to scale the complete chart (i.e. to change width and height in a proportional way), the \texttt{scale}-option can be used:
356 \begin{quote}\small
357 \begin{verbatim}
358 \begin{bchart}[max=10,step=2,scale=0.7]
359 \bcbar{7.5}
360 \bcbar{3.2}
361 \end{bchart}
362 \end{verbatim}
363 \end{quote}
364 \begin{quote}
365 \begin{bchart}[max=10,step=2,scale=0.7]
366 \bcbar{7.5}
367 \bcbar{3.2}
368 \end{bchart}
369 \end{quote}
370 Note that this does not change the size of the text either, only the bars and axes. To scale everything, including text, the chart environment has to be put into a \texttt{scalebox}-command instead:
371 \begin{quote}\small
372 \begin{verbatim}
373 \scalebox{0.7}{
374 \begin{bchart}[max=10,step=2]
375 \bcbar{7.5}
376 \bcbar{3.2}
377 \end{bchart}}
378 \end{verbatim}
379 \end{quote}
380 \begin{quote}
381 \scalebox{0.7}{
382 \begin{bchart}[max=10,step=2]
383 \bcbar{7.5}
384 \bcbar{3.2}
385 \end{bchart}}
386 \end{quote}
387
388 These three ways to change the size of the chart can all be combined to produce different kinds of scaling effects:
389 \begin{quote}\small
390 \begin{verbatim}
391 \scalebox{0.7}{
392 \begin{bchart}[max=10,step=2,width=4cm,scale=0.7]
393 \bcbar{7.5}
394 \bcbar{3.2}
395 \end{bchart}}
396 \end{verbatim}
397 \end{quote}
398 \begin{quote}
399 \scalebox{0.7}{
400 \begin{bchart}[max=10,step=2,width=4cm,scale=0.7]
401 \bcbar{7.5}
402 \bcbar{3.2}
403 \end{bchart}}
404 \end{quote}
405
406
407 \section{Known Issues}
408
409 There are some known issues with this package. Below, they are discussed and workarounds are presented.
410
411 When using fractions in the \texttt{step}-option, sometimes rounding errors become apparent:
412 \begin{quote}\small
413 \begin{verbatim}
414 \begin{bchart}[step=0.2,max=1]
415 \bcbar{0.76}
416 \end{bchart}
417 \end{verbatim}
418 \end{quote}
419 \begin{quote}
420 \begin{bchart}[step=0.2,max=1]
421 \bcbar{0.76}
422 \end{bchart}
423 \end{quote}
424 As a workaround, the \texttt{steps}-option can be used instead, where all marks must be listed explicitly:
425 \begin{quote}\small
426 \begin{verbatim}
427 \begin{bchart}[steps={0.2,0.4,0.6,0.8,1},max=1]
428 \bcbar{0.76}
429 \end{bchart}
430 \end{verbatim}
431 \end{quote}
432 \begin{quote}
433 \begin{bchart}[steps={0.2,0.4,0.6,0.8,1},max=1]
434 \bcbar{0.76}
435 \end{bchart}
436 \end{quote}
437
438 Another known issue is the fact that you can get a \LaTeX{} error message saying ``Dimension too large'' when using large numbers:
439 \begin{quote}\small
440 \begin{verbatim}
441 \begin{bchart}[max=20000]
442 \bcbar{18000}
443 \end{bchart}
444 \end{verbatim}
445 \end{quote}
446 A possible workaround is moving the decimal point of all numbers by a couple of digits and manually adding the real value with the \texttt{value}-option:
447 \begin{quote}\small
448 \begin{verbatim}
449 \begin{bchart}[max=20]
450 \bcbar[value=18000]{18}
451 \end{bchart}
452 \end{verbatim}
453 \end{quote}
454 \begin{quote}
455 \begin{bchart}[max=20]
456 \bcbar[value=18000]{18}
457 \end{bchart}
458 \end{quote}
459 This is only a partial workaround though, since the numbers on the x-axis cannot be manually modified.
460
461 \end{document}
462