4

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.

Taendyr
  • 41

2 Answers2

6

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}
\DTLloaddb[keys={Artist,Album,Remark}]{test}{test.csv}
\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>>=
x <- read.csv("test.csv",header = T)
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:

mwe

Fran
  • 80,769
5

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.

Peter Wilson
  • 28,066