Book Image

LaTeX Cookbook

By : Stefan Kottwitz
Book Image

LaTeX Cookbook

By: Stefan Kottwitz

Overview of this book

LaTeX is a high-quality typesetting software and is very popular, especially among scientists. Its programming language gives you full control over every aspect of your documents, no matter how complex they are. LaTeX's huge amount of customizable templates and supporting packages cover most aspects of writing with embedded typographic expertise. With this book you will learn to leverage the capabilities of the latest document classes and explore the functionalities of the newest packages. The book starts with examples of common document types. It provides you with samples for tuning text design, using fonts, embedding images, and creating legible tables. Common document parts such as the bibliography, glossary, and index are covered, with LaTeX's modern approach.You will learn how to create excellent graphics directly within LaTeX, including diagrams and plots quickly and easily. Finally, you will discover how to use the new engines XeTeX and LuaTeX for advanced programming and calculating with LaTeX. The example-driven approach of this book is sure to increase your productivity.
Table of Contents (19 chapters)
LaTeX Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Building a bar chart


A classic way of displaying categories with corresponding values is a bar chart. It consists of rectangular bars, and they are proportional to the represented values. The main purpose is to visually compare those values.

We will draw a chart visualizing web forum statistics.

How to do it...

We will use the pgfplots package. It's for natively plotting in LaTeX with a convenient user interface. We will use it to produce a horizontal bar chart.

Perform these steps:

  1. Start with a document class:

    \documentclass{article} 
  2. Load the pgfplots package:

    \usepackage{pgfplots}
    \pgfplotsset{width=7cm,compat=1.8}
  3. Begin the document:

    \begin{document}
  4. Begin a TikZ picture, which will be the container for the plot:

    \begin{tikzpicture}
  5. Open an axis environment:

      \begin{axis}
  6. Give options to the axis:

     [
        title    = Contributions per category
                   at LaTeX-Community.org,
        xbar,
        y axis line style = { opacity = 0 },
        axis x line       = none,
        tickwidth         = 0pt,
        enlarge...