Donnerstag, 5. Februar 2015

LaTex, datatool and MS Excel: Troubleshooting

Recently I got the time to write some proof of concept LaTeX and tinker with packages that I hadn't played with before. I wanted to share a few of the experiences here that will probably help debugging for some of you easier:

XLSX to datatool
Theoretically datatooltk should be able to handle xls files and also umlauts and also newlines inside a cell. Practically it didn't work for me. That is version 1.4 from 2015-01-23. Since I didn't have too much time, I exported the table as csv from Excel and continued from there.

1. Encoding

Excel still hasn't gotten around to use UTF-8. So you need to do some re-encoding of your csv file to utf-8. Linux luckily has onboard tools to do so:

iconv -f ISO-8859-1 -t UTF-8 excel-export.csv > excel-utf8.csv

2. Special Characters

Datatool needs to load files with '}' etc. with \DTLloadrawdb and not with \DTLloaddb.

3. Import of Packages

By the way, loading package inputenc before datatool will throw you this following error:

! Package inputenc Error: Keyboard character used is undefined

and loading it before \DTLloadrawdb will likely throw you this error:

! Undefined control sequence.

4. Umlauts and Datatool

It looked like datatool should be able to handle umlauts, but it didn't. So I quickly replaced the umlauts:

sed '
s/ä/\"a/g
s/ö/\"o/g
s/ü/\"u/g
excel-utf8.csv > data.csv

If you have the German "sharp s", a French cedille or accents, this is the time to take care of it. Now there shouldn't be any problem left importing the csv.

5. Multicolumn

Drawing the table itself isn't a big deal, just once you start messing with multicolumns it can. It doesn't like if there is something infront of a multicolumn.

! Misplaced \omit. \multispan ->\omit                     \@multispan
is the error you'll see. Play around with what happens when you add \\ infront of it or \hline. Sometimes that's what does the job.

6. Vwcols, Multicols and Variable Width

I wasn't capable of easily having two columns with different widths and different colors easily with either of these packages. Minipages did the trick.

\begin{minipage}{0.6\textwidth}
\dots
\end{minipage}\hfill\color{red}{\vline}\hfill
\begin{minipage}{0.3\textwidth}}
\dots
\end{minipage}

As a friend once said, in LaTeX it's all about finding the right package.

7. Horizontal lines

An error I ran into from time to time:

! Misplaced \noalign.
\hline ->\noalign
{\ifnum 0=`}\fi \let \hskip \vskip \let \vrule \hrule \let...

This happened especially when the newline was in a conditional before the horizontal line. The problem was solved by moving the newline out of the conditional and infront of the hline

\\\hline

8. Cell borders

Unfortunately cell borders kept disappearing for no obvious reason when I used \cellcolor. After a bit of frustration and research I had to discover that this is not a LaTeX problem, but rather a pdf / pdf viewer problem. Printing the document gave me nice cell borders. You can also zoom in and out, and borders will show and disappear.


This is everything but the clean and real solutions, but it might come in useful while playing with any of those packages. If you have better solutions or comments, feel free to share!

Keine Kommentare: