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$

\begin{table}[]
\begin{tabular}{llllll}
 &  &  &  &  & 
\end{tabular}
\caption{}
\label{tab:my-table}
\end{table}

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

\begin{table}[]
\begin{tabular}{llllll}
 
 &  &  &  &  &  \\
 &  &  &  &  &  \\
 &  &  &  &  & 
\end{tabular}
\caption{}
\label{tab:my-table}
\end{table}

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
  2 
  3 echo " " > data.txt
  4 echo "\begin{table}[]" > data.txt
  5 echo "\begin{tabular}{llllll}" >> data.txt
  6 #wc -l data.txt
  7 
  8 for i in {1..10..1}
  9   do 
 10 
 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

\begin{longtable}{llllll}
\end{longtable}

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

You can find me on Friendica at zleap@social.isurf.ca


MastodonPeertubeQoto sign up

Donate using Liberapay