Tag Archives: pas-tableur

past-tableur filled

Using the pas-tableur style for spreadsheets in LaTeX

One of LaTeX's strengths is its ability to typeset publication quality tables using the booktabs but sometimes we need something that look like a spreadsheet. There are several solutions to this problem. If we are working in Excel, we can, for example, select the necessary cells of interest and create an image to be inserted into our document. There are some problems with this solution. As we are all too aware, things change during the course of writing and if our spreadsheet changes, we must go through the process of recreating our image and inserting the new image into our LaTeX code.

Though it takes some time and effort (in the beginning) there are several good reasons to rendering something that looks like a spreadsheet in code. For one, we can easily see the code to make sure everything is correct before we compile but the biggest advantage is that any changes can be made easily. We don't have to fire up Excel (shudder) and so save time during the editing process. As ideal as this solution is, there is one problem. A huge one. It takes some planning and prep for it to move smoothly.

To get an idea of how you can do this you can take a look at the "Typesetting a table to look like a spreadsheet" discussion on StackExchange. It's not difficult and we see one solution using the array and colortbl packages and another in TikZ. Of course, there is a problem of utility. These solutions are fine if you just need to show one spreadsheet image. What if you have many spreadsheets, for example, in the case where you're writing a book? How can you make this easier? You can use the TikZ pas-tableur package by Stéphane Pas­quet.

Getting Started

Though the pas-tableur package documentation is written in French, the package is easy to utilize. To start you just need to load the package:

Now you can start drawing your spreadsheets

Drawing a Spreadsheet

The tableur command automatically creates a spreadsheet with the tableur command. As this uses the TikZ package, the command must be enclosed within the tikzpicture environment. The command syntax is:

To create a 3 by 4 spreadsheet, we use:

which looks like

spreadsheet

A pas-tableur spreadsheet with no options defined.

Changing colors up

This isn't bad as things go but what if you need to customize things a bit? Turns out this is simple. You can define these options in the preamble.

The above are the default options. What is we wanted to change the color of the top part of the header to yellow?

which gives us the output:

pas-tableur spreadsheet

A pas-tableur spreadsheey with the top part of the header colored in yellow.


and as Bermuda Sand is a wonderful color, we add the command:

and we get:
pas-tableur yellow

A pas-tableur spreadsheet with the top part of the header colored in yellow and the bottom part colored in Bermuda Sand.


Now that you're adjusted the header colors, what if you needed to change the cell lines to a nice dark golden color?

which looks like:
pas-tableur spreadsheet

A pas-tableur spreadsheet with the color of the cell lines changed.


Changing cell size

Now that we have had fun with changing the colors of our spreadsheet, what if we just wanted to change the cell width and height? For that we turn to the colminwidth and lineminheight commands.

Our extra long spreadsheet looks like this:

pas-tableur spreadsheet

Image showing a pas-tableur spreadsheet with a long cell width.


We can do the same thing for the cell height:

which looks like:
pas-tableur tall cells

A pas-tableur spreadsheet with extra tall cells


Filling the cells

Drawing empty spreadsheets are fun but generally we fill spreadsheets with text and formulas. This can be done with the celtxr command.

Now we can fill our spreadsheet:

which looks like:

past-tableur filled

The pas-tableur spreadsheet has been filled with text and formulas.


Selecting and Highlighting Cells

Selecting a Single Cell

You may need to select or highlight cells to illustrate your point. For that, we turn to the selecCell command.

So if we wanted to select the C2 cell of our spreadsheet:

Selecting Multiple Cells

Sometimes we need to highlight, not one, but a group of cells. For that we turn to the multiSelec command:

So if we wanted to highlight B2 to D4 in our spreadsheet:

which looks like:

pas-tableur spreadsheet

Here we can see the B2 and D4 cells highlighted.


Changing the colors

But what if you wanted to change the color of the highlighted headers? For that we define the blueSelecCellTop and the blueSelecCellBottom colors in the preamble:

which looks like:

pas-tableur spreadsheet

Here we change the colors of the top and bottom parts of the highlighted cells.


Conclusion

The pas-tableur package is an easy to use LaTeX package for generating spreadsheet images. Of course, you can use your favorite spreadsheet, capture it as an image and integrate it into your document but the package offers some advantages. As everything is generated in LaTeX code, you can add spreadsheets and make edits easily--the process becomes a part of your writing which is something we all love about LaTeX.

I found the package easy to use and understand and would recommend it to anyone who needs to generate spreadsheet images into their document.