Archive for September, 2006

LaTeX: footnotes in tables

Although an apparently widely known LaTeX issue, I came across it just today. Fact is if you use \footnote inside a \tabular environment, the footnote will be “trapped” inside the table, and actually never get displayed at all in the output.

You can find some possible solutions for that at the UK TeX FAQ on the Web.

The trick I’ll comment here is to use \tabularx, which is covered in the link above, and also at J.L. Diaz’s LaTeX blog[es].

The “problem” is that \tabularx requires a fixed table width value to be input by the user, so the following will fail misserably:

\usepackage{tabularx} % required in the preamble
\begin{tabularx}{100mm}{|c|c|} \hline
A & B \\ \hline
C & D \\ \hline
\end{tabularx}

Why? Because the {c} especification (to center the text inside the cell) makes the affected column as wide as necessary, not more (so will {r} or {l}). The output can be seen below:

The effect of the whole table being actually wider than the sum of the integrating colums could be partially “concealed” if the \hlines were eliminated, but the table would still be actually incorrectly wide, which would make things like aligning the whole table “fail” (to the eye).

Fortunately, the tabularx package provides a way to tell LaTeX that a column must be of the necessary width, so that the sum of colum widths equals the total column width. This is the {X} keyword (notice the capitalization of the “X”). E.g.:

\begin{tabularx}{100mm}{|c|X|} \hline
A & B \\ \hline
C & D \\ \hline
\end{tabularx}

This makes the first column just as wide as needed, not more (the {c}), and then, the second column will be as wide as needed to reach the 100mm. The output:

If multiple columns are given the {X} keyword, they will all have the same width, precisely the one required to meet the total table width.

Comments (3)

Sudaku released

I previously posted about the sudoku fever that had attacked my family. I have found amusing solving some sudokus, but what I really thought was interesting was making a computer program to solve them automatically. Not that it would be more “challenging” (some sudokus are quite difficult), just more fun for me.

OK, so that I did, and today I have released a Perl program that (hopefully) solves any sudoku we feed to it. The program is called Sudaku (well, one sweats when solves a sudoku, doesn’t one?), and can be freely downloaded from my home page. I have licensed it under the GPLv2.

Yes, I know there are other sudoku solvers around, probably better than mine, on top of that. However, I just wanted to make it, and releasing it may help someone, or (more probably) even me, if some better programers than me out there e-mail me proposing changes/corrections.

What the heck, I just felt like releasing it! :^)

Comments

« Previous Page « Previous Page Next entries »