# Organising a table from an external file

I'd like to create a tab containing information about music albums (for example, a column with the artist, a column with the album title, a column with a remark, etc.).

I don't want to do something like

\begin{tabular}{c|c|c}
Artist & Album & Remark\\
MyArtist1 & MyAlbum1 & MyRemark1\\
MyArtist2 & MyAlbum2 & MyRemark2
\end{tabular}


Since this is a list I will update often and I want it to be sorted (alphabetically, by year, etc.).

The way I thought was to store all the information of the albums in an external file and use it to create my tab (like for the references for example). Something like

@album{Name
\title='MyTitle',
\year='1968',
\artist='MyArtist'
}


Does there already exists a package to do this, or do I need to code it myself? If so, I take every ideas you have.

If what you do is not more complex than you show, I simply will make a CSV file:

test.csv:

Artist,Album,Remark
MyArtist1, MyAlbum1, MyRemark1
MyArtist3, MyAlbum2, MyRemark1
MyArtist1, MyAlbum3, MyRemark2
MyArtist2, MyAlbum4, MyRemark2


Advantage: That can updated at easily convenience in any text editor, any spreadsheet, or even form the command line:

echo "MyArtist4, MyAlbum5, MyRemark3" >> test.csv


Then can be imported with LaTeX tools in different ways (for instance, see here). Whith datatool is easy sort this data:

mew.tex:

\documentclass{article}
\usepackage{datatool}
\begin{filecontents}{test.csv}
Artist,Album,Remark
MyArtist1, MyAlbum1, MyRemark1
MyArtist3, MyAlbum2, MyRemark1
MyArtist2, MyAlbum3, MyRemark2
MyArtist1, MyAlbum4, MyRemark2
\end{filecontents}
\begin{document}
\DTLsort{Artist}{test}
\begin{table} \caption{Test}
\medskip\centering
\DTLdisplaydb{test}
\end{table}
\end{document}


If you need some more that sort a small table another alternative is load the csv file in R, manage in any way (sort by Artist, select a subset by some remark, etc.) and then produce a table via xtable, for instance.

mwe.Rnw

\documentclass{article}
\usepackage{booktabs}\belowcaptionskip1ex
\begin{document}
<<Mytable,results="asis",echo=F>>=
library(xtable)
print(xtable(x[order(x\$Artist),],caption="Test"),
include.rownames=F, booktabs=T, caption.placement="top" )
@
\end{document}


If you do not kow about knitr and .Rnw files, install Rstudio, or alternatively load it in Overleaf as mwe.Rtex, the result must be:

I wanted something similar, although not in table form, for my book and other collections. I based this on bibtex; feed in the book database file and get it all sorted. I wrote this up as Peter Wilson, A personal book catalogue: bookdb, TUGboat, no 1, pp 67-71, 2016.

It is available at https://tug.org/TUGboat/tb37-1/tb115wilson.pdf

Maybe it will give you, or somebody else, an idea or two.

• +1: But is bibtex (vs. biblatex) still relevant for this? Dec 29 '20 at 1:31
• @Dr.ManuelKuehner I don't know. It's been a long time since I used bibtex and have never knowingly used biblatex. Perhaps you can tell me. Dec 29 '20 at 18:14
• @Dr.ManuelKuehner Having re-read the article I see that I did look at using biblatex but bibtex fitted my needs better. Dec 29 '20 at 18:43
• Thanks for the follow-up! It always amazes me what people can do with the provided toolchain of LaTeX and friends :). Dec 29 '20 at 22:29