416 lines
9.4 KiB
TeX
416 lines
9.4 KiB
TeX
\documentclass[]{article}
|
|
\usepackage{barchart}
|
|
\usepackage{vmargin}
|
|
|
|
\setmarginsrb { 1.0in} % left margin
|
|
{ 0.6in} % top margin
|
|
{ 1.0in} % right margin
|
|
{ 0.8in} % bottom margin
|
|
{ 20pt} % head height
|
|
{0.25in} % head sep
|
|
{ 9pt} % foot height
|
|
{ 0.3in} % foot sep
|
|
|
|
\title{\texttt{barchart}: Easy Bar Chart in \LaTeX
|
|
\medskip\\
|
|
\large Version 0.1.0
|
|
}
|
|
|
|
\author{Frederik Vanggaard}
|
|
\date{\today}
|
|
|
|
\begin{document}
|
|
|
|
\maketitle
|
|
|
|
\section{Introduction}
|
|
\texttt{barchart} is a \LaTeX\space package for creating simple and easy to use bar-chart. The package is inspired by \texttt{bchart} by Tobias Kuhn. \texttt{barchart} provides an easy way to create vertical barcharts using Tikz.
|
|
|
|
\section{Charts}
|
|
\texttt{barchart} comes with a variety of customization options for both the overall chart and for each individual bar. A simple chart can be done like this:
|
|
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}
|
|
\barc{5}
|
|
\barc{7}
|
|
\barc{3}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}
|
|
\barc{5}
|
|
\barc{7}
|
|
\barc{3}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
The only arguments that are mandatory is the bar value. The charts can be changed using a few simple options such as \texttt{min}, \texttt{max} and \texttt{step}.
|
|
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[min = 0, max = 60, step = 10, height=0.25em]
|
|
\barc{30}
|
|
\barc{20}
|
|
\barc{50}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\begin{quote}\small
|
|
\begin{barchart}[min = 0, max = 60, step = 10, height=0.25em]
|
|
\barc{30}
|
|
\barc{20}
|
|
\barc{50}
|
|
\end{barchart}
|
|
\end{quote}
|
|
|
|
\texttt{height} is used to set the height of the whole chart. Omitting a height on charts with large \texttt{max} values will make the chart enormous.
|
|
|
|
\section{Bars}
|
|
Each bar can be customized to your liking. This can be done using \texttt{color}, \texttt{width} and \texttt{plain}.
|
|
\texttt{color} changes the color of each bar like:
|
|
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[step = 2]
|
|
\barc[color=yellow!60]{5}
|
|
\barc[color=orange!60]{7}
|
|
\barc[color=cyan!60]{3}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}[step = 2]
|
|
\barc[color=yellow!60]{5}
|
|
\barc[color=orange!60]{7}
|
|
\barc[color=cyan!60]{3}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
\texttt{width} changes the width of each bar:
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[step = 2]
|
|
\barc[width=40pt]{5}
|
|
\barc[width=30pt]{7}
|
|
\barc[width=50pt]{3}
|
|
\barc[width=20pt]{3}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}[step = 2]
|
|
\barc[width=40pt]{5}
|
|
\barc[width=30pt]{7}
|
|
\barc[width=50pt]{3}
|
|
\barc[width=20pt]{3}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
Using less than \texttt{20pt} is not recommended. Instead of using pre-defined step as the examples have shown so far, \texttt{steps} can be used.
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[steps = {1,3,5,7,10}]
|
|
\barc{5}
|
|
\barc{7}
|
|
\barc{3}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}[steps = {1,3,5,7,10}]
|
|
\barc{5}
|
|
\barc{7}
|
|
\barc{3}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
\texttt{plain} is a boolean which can either be \texttt{true} or \texttt{false} and removes the label on the bar.
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}
|
|
\barc{5}
|
|
\barc[plain=true]{7}
|
|
\barc[plain=true]{3}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}
|
|
\barc{5}
|
|
\barc[plain=true]{7}
|
|
\barc[plain=true]{3}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
|
|
|
|
|
|
\section{Skips}
|
|
Between each bar a skip can be implemented to have more or less room. This is done using \texttt{\textbackslash barcskip\{\}}.
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}
|
|
\barc{5}
|
|
\barcskip{10pt}
|
|
\barc{7}
|
|
\barcskip{20pt}
|
|
\barc{3}
|
|
\barcskip{30pt}
|
|
\barc{2}
|
|
\barcskip{-5pt}
|
|
\barc{6}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}
|
|
\barc{5}
|
|
\barcskip{10pt}
|
|
\barc{7}
|
|
\barcskip{20pt}
|
|
\barc{3}
|
|
\barcskip{30pt}
|
|
\barc{2}
|
|
\barcskip{-5pt}
|
|
\barc{6}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
The skips can either be made with positive or negative \texttt{pt} or using default skip sizes as \texttt{\textbackslash smallskip}, \texttt{\textbackslash medskip} and \texttt{\textbackslash bigskip}.
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}
|
|
\barc{5}
|
|
\smallskip
|
|
\barc{7}
|
|
\medskip
|
|
\barc{3}
|
|
\bigskip
|
|
\barc{2}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}
|
|
\barc{5}
|
|
\smallskip
|
|
\barc{7}
|
|
\medskip
|
|
\barc{3}
|
|
\bigskip
|
|
\barc{2}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
|
|
\section{Labels}
|
|
The package also include various ways of labeling the charts. Both the chart and its individual bars can be labeled.
|
|
|
|
The chart can be labeled using:
|
|
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[label= A nice chart]
|
|
\barc{5}
|
|
\barc{7}
|
|
\barc{3}
|
|
\barc{2}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}[label= A nice chart]
|
|
\barc{5}
|
|
\barc{7}
|
|
\barc{3}
|
|
\barc{2}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
Each bar can also have their own label. These labels are positioned below the x-axis.
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[label=A nice chart]
|
|
\barc[label=Some]{5}
|
|
\barc[label=Nice]{7}
|
|
\barc[label=Labels]{3}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}[label=A nice chart]
|
|
\barc[label=Some]{5}
|
|
\barc[label=Nice]{7}
|
|
\barc[label=Labels]{3}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
These labels can also be rotated, so they are easier to read using \texttt{rotation=true}.
|
|
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}
|
|
\barc[label=Some, rotation=true]{5}
|
|
\barc[label=Nice, rotation=true]{7}
|
|
\barc[label=Labels, rotation=true]{3}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}
|
|
\barc[label=Som, rotation=truee]{5}
|
|
\barc[label=Nice, rotation=true]{7}
|
|
\barc[label=Labels, rotation=true]{3}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
\section{Scaling}
|
|
If the charts become too big or small, it is possible to scale them using \texttt{scale}.
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[scale = 0.5]
|
|
\barc{5}
|
|
\barc{7}
|
|
\barc{3}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}[scale=0.5]
|
|
\barc{5}
|
|
\barc{7}
|
|
\barc{3}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
But sometimes it is not enough to just scale the chart. Using \texttt{height} it is possible to set a fixed height of the chart.
|
|
|
|
\begin{center}
|
|
\begin{minipage}[l][][c]{0.45\linewidth}
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[min=0, max=500,
|
|
step = 100, height=0.05ex]
|
|
\barc{500}
|
|
\barc{70}
|
|
\barc{300}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
\end{minipage}
|
|
\quad
|
|
\begin{minipage}[r][][c]{0.45\linewidth}
|
|
\begin{barchart}[min=0, max=500, step = 100, height=0.05ex]
|
|
\barc{500}
|
|
\barc{70}
|
|
\barc{300}
|
|
\end{barchart}
|
|
\end{minipage}
|
|
\end{center}
|
|
|
|
|
|
\section{Known Issues}
|
|
When using large values for each bar, it is important to set a fixed height like:
|
|
\begin{quote}\small
|
|
\begin{verbatim}
|
|
\begin{barchart}[label= A nice chart, min=0, max=100, height=0.2ex, step=20]
|
|
\barc{50}
|
|
\barc{70}
|
|
\barc{30}
|
|
\barc{20}
|
|
\barc{50}
|
|
\barc{70}
|
|
\barc{30}
|
|
\barc{20}
|
|
\barc{50}
|
|
\barc{70}
|
|
\barc{30}
|
|
\barc{20}
|
|
\end{barchart}
|
|
\end{verbatim}
|
|
\end{quote}
|
|
|
|
\begin{quote}\small
|
|
\begin{barchart}[label= A nice chart, min=0, max=100, height=0.2ex, step=20]
|
|
\barc{50}
|
|
\barc{70}
|
|
\barc{30}
|
|
\barc{20}
|
|
\barc{50}
|
|
\barc{70}
|
|
\barc{30}
|
|
\barc{20}
|
|
\barc{50}
|
|
\barc{70}
|
|
\barc{30}
|
|
\barc{20}
|
|
\end{barchart}
|
|
\end{quote}
|
|
\end{document} |