Script for $\LaTeX$ Tables

I was asked in irc ( ##chemistry on frenode) about a project to create a table for periodic table data in $\LaTeX$.

This post, is meant to be a rough guide. You are expected to do your own research in to any specific features you need.

As there are now about 120 elements, doing this manually could be rather long winded. So I am trying to develop a small shell script to help with this process.

Firstly Looking at loops in Bash

now how to generate a basic table in $\LaTeX$

 &  &  &  &  & 

This is for a 1 row table, to add multiple rows, you need to add \ at the end of the row as in:-

 &  &  &  &  &  \\
 &  &  &  &  &  \\
 &  &  &  &  & 

The following shell script should help us with this.

Please note that the \, should be removed from the very last row.

I have added a script for 10 rows. This can be changed via the shell script.

 1 #!/bin/bash
  3 echo " " > data.txt
  4 echo "\begin{table}[]" > data.txt
  5 echo "\begin{tabular}{llllll}" >> data.txt
  6 #wc -l data.txt
  8 for i in {1..10..1}
  9   do 
 11      #echo "hello"
 12      echo  "&  &  &  &  & \\" >> data.txt
 13  done
 14 #wc -l data.txt
 15  echo  "\end{tabular}" >> data.txt
 16  echo  "\caption{}" >> data.txt
 17  echo  "\label{tab:my-table}" >> data.txt
 18  echo  "\end{table}" >> data.txt

Required table headings were : atom ; r atomic ; density ; Tf ; Tg ;... ?

Table headings are obviously at the top, therefore, once you have run the script and generated the right number of rows amending the first row to

& atom & r atomic & density & Tf & Tg \

Should give the required headings

I have added some word count (wc) to help with diagnostics.

You will need to change the output file extension to .tex for a $\LaTeX$ file. I'll leave it as data.txt as you need to add the other components of a $\LaTeX$ document anyway.

If the table spans more than 1 page then the table should use


#chemistry, #typesetting, #bash, #LaTeX, #tables, #scripting

You can find me on Friendica at