Ceci est une ancienne révision du document !
I have found that, once a person gets bitten by the LaTeX bug, there is never a lack of something to do or learn. All it takes is a task that needs to be done, a desire to take a path less travelled to complete the task (with style!), and a person is off and away into the LaTeX way of doing things. Sometimes we have to use the software provided in an office suite, because they do some (OK, many) things well. I am typing this in LibreOffice Writer because that is the format that FullCircle accepts. And that is OK, as there are things that may be best left to the office suite, like spreadsheets. The right tool for the job.
J'ai constaté que, une fois qu'une personne est victime d'un bogue de LaTeX, il ne finit jamais de faire ou d'apprendre quelque chose. Tout ce qu'il faut c'est une tâche qui doit être effectuée, une envie de prendre un chemin moins compliqué pour terminer la tâche (avec style !), et une personne va loin dans la manière de faire les choses de LaTeX. Parfois, nous devons utiliser un logiciel fourni dans une suite bureautique, parce qu'ils font certains (ou beaucoup) choses correctement. J'écris ceci dans LibreOffice Writer parce que c'est le format que FullCircle accepte. Et c'est OK, car il y a des choses qui peuvent être mieux traitées par la suite bureautique, comme des feuilles de calcul. Le bon outil pour ce travail.
In my last article, I demonstrated that LaTeX code (or any markup code) can be inserted into data that is in a spreadsheet to format the data for publication. This comes in handy for creating something like a pocket address book from information in a tabular database.
Dans mon dernier article, je démontrais que le code LaTeX (ou tout autre code de balise) peut être inséré dans des données se trouvant dans une feuille de calcul pour formater les données en vue de la publication. C'est très pratique pour créer quelque chose comme un carnet d'adresses de poche à partir d'informations contenues dans une base de données sous forme de tableau.
Tabular data and LaTeX are not strangers to one another, and the combination is covered in many of the basic LaTeX manuals. There are also special packages written to help us communicate tabular data with LaTeX, most of these packages have detailed manuals of their own like the 38-page manual for the package csvsimple, a package that I hope to cover in a future article. Then there is Spreadtab.
Les données de tableau et LaTeX ne sont pas étrangers l'un à l'autre, et la combinaison est couverte dans la plupart des manuels de base LaTeX. Il existe également des paquets spéciaux écrits pour nous aider à faire communiquer des données tabulaires avec LaTeX, la plupart de ces paquets ont leurs propres manuels bien détaillés comme le manuel de 38 pages pour le paquet csvsimple, un paquet que je souhaite couvrir dans un futur article. Ensuite, il y a Spreadtab.
Spreadtab is a LaTeX package that can bring some of the features of a spreadsheet to your LaTeX documents. Or, as Christian Tellechea, the creator of the package, said in the abstract of the (extremely well written) manual:
Spreadtab est un paquet LaTeX qui peut apporter quelques-unes des caractéristiques d'un tableur pour vos documents LaTeX. Ou, comme Christian Tellechea, le créateur du paquet, l'a dit dans le résumé du (très bien écrit) manuel:
“This package provides spreadsheet features for LaTeX table environments.
The main feature allows the user to construct tables in a manner similar to a spreadsheet where cells are used in formulas to generate values in other cells. The package computes the formulas in the correct order, and finally displays the table with the numeric results.”
Ce paquet offre des fonctionnalités de feuille de calcul pour les environnements de tableau LaTeX
La principale fonctionnalité permet à l'utilisateur de construire des tableaux d'une manière similaire à une feuille de calcul dans laquelle les cellules sont utilisées dans des formules pour générer des valeurs dans d'autres cellules. Le paquet calcule les formules dans le bon ordre, et enfin affiche la tableau avec les résultats numériques.
Up until the time this package was written, there was nothing in the LaTeX environment that could do this. Christian Tellechea took this on as a programming exercise. Once again, someone scratches an itch and the world is a better place for it. Thank you, Christian!!!
To whet your appetite for Spreadtab, I will demonstrate some of the basic things you can do with this package. One of the incentives is to Keep It Simple Silly (KISS) – I am not a mathematician by any stretch of the imagination, so I better keep this down to basic bean counting.
What I will show you here can be done with a spreadsheet, however if you want to place your spreadsheet information into a LaTeX document, then you will find this package useful. Or, if you have a document with calculations that you want to reuse, this package can help you create the base original document.
Everything starts in a new directory (rule number one) and a preamble at the top of your file (see box above)
The tabular data that you want to include must be described to the package: • {tabular} tells LaTeX “here comes some information in tabs” • {with lower case “l”s} tells LaTex how many tabs there are • the “|” tells LaTeX where to place any vertical lines.
The “&” signals a cell or tab and labels in the cells are preceded with the “@”. Note that, within the tabular environment, & does not require a “\” before it.
To end this environment use this command:
\end{spreadtab}
Let’s set up a page with five tabs, a vertical line between tab 4 and 5, and with labels for columns and rows.
Given the above, our document can look like that shown below after the preamble.
Notice how nicely I have lined up the “&”. They do not have to be, and as you add or subtract data they will move around – that is OK. However, keeping everything aligned will help you correct errors and/or prevent you from getting dizzy.
You will have to visualise that there are five columns here, and four rows, and, just like a spreadsheet, columns have a letter and rows have a number. This will enable us to make calculations, just like in a spreadsheet. So let’s add some numbers and calculations (see box top right).
And all of that will give us: In my example here, the data is flush left because of the five letter l’s in the tabular command. To move data to the right replace the l’s with r’s, and c will place the data in the centre of the column.
Just for a giggle, lets change the rat “3” with the word “pi”.
You can also make calculations within tabs with the * and / – if you place 8/2 in a tab, it will show a 4. Place a 8*5 in a tab and it will show a 40.
Let’s put this to work: Here (previous page, bottom right) is an invoice for a growing concern.
The command \STautoround*{2} provides 2 decimal points with the “*” filling in zeros when necessary.
Placing a % at the start of a line hides it from LaTeX but the A B C can help us keep track of the columns.
The @ 1 @ 2 @ 3 gives us the line numbers, but as “words” – so there are no decimal places.
It looks like the image above.
The only “Gotcha” I could find is things can go haywire if you have a blank line within the spreadtab environment.
I have just scratched the surface with Spreadtab, really. My tables here are very simple, but what you will see in the spreadtab manual are much more complex and interesting. You can download the manual from https://www.ctan.org/pkg/spreadtab?lang=en
Once again, a big thank you / merci beaucoup to Christian Tellechea for all of his work on this package and the documentation.
John Eddie Kerr is a law librarian in Guelph, Ontario Canada. Ubuntu Linux is his desktop at home and at work. Xubuntu powers his Raspberry Pi 3 and Ubuntu Mate powers his Raspberry Pi 2.