CV Tip: Align Columns of Different LaTeX Tables with \settowidth
by Alessandro
The problem with tables in a CV is that they are usually typeset as pairs of date => some job title, or piece of research.
For example, on the left, you can see three different sections:
- A Work Experience section;
- The Education section;
- Another Section for Scholarships
So what happens when you are typesetting the columns of the document, especially the ones with dates?
Dates can be of different length, consider for a moment how Summer and Fall 2010 will generate totally different column width, and the style of a one page document like a CV will suffer from this asymmetry.
So the idea I tried to implement in the document is that of considering all dates as if they belong to the same column (and to the same table obviously), therefore the leftmost column contaning the dates will be as wide as the widest date element.
This date element happens to be Summer 2007, which is quite long indeed, therefore all we need to do now is to create a new length that will store the Summer 2007 length and apply it to the columns.
1. Length Manipulation Macros: \setlength, \newlength, \settowidth
1.a Declaring and Naming a new Dimension Container
\newlength{\datebox}
1.b Storing the length of a Text String into the just created Length \datebox
\settowidth{\datebox}{Summer 2007} % string of text works here \typeout{\the\datebox} % outputs 75.84961pt
1.c Manually assigning a value to a previously declared Length
\setlength{\datebox}{<dimension>} % string of text doesnt work here \typeout{\the\datebox} % outputs <dimension>pt
Example usage of \setlength might be
\setlength{\datebox}{1em} \setlength{\datebox}{1mm} \setlength{\datebox}{1cm} \setlength{\datebox}{1pt}
2. Setting the Fixed Table Column Width
Option 1 involves setting the left hand side column as a justified paragraph of length \datebox.
%Table 1 \begin{tabular}{p{\datebox}l} % first row [...] & % first cell - width: \datebox [...] % second cell - width: variable %Table 2 \begin{tabular}{p{\datebox}l} % first row [...] & % first cell - width: \datebox [...] % second cell - width: variable \end{tabular}
Another option is to use \parbox{dimen}{text}
%Table 1 \begin{tabular}{rl} %notice r in place of p{\datebox} % first row \parbox{\datebox}{[...text...]} & % first cell - width of the parbox: \datebox [...] % second cell - width: variable %Table 2 \begin{tabular}{p{\datebox}l} % first row \parbox{\datebox}{[...text...]} & % first cell - width of the parbox: \datebox [...] % second cell - width: variable \end{tabular}
3. Final Result, as per Option 2 \parbox
Useful Links on the Topic: Wikibooks
Related posts:


Comments
Nice Work, but i didn’t get it how you set the date right aligned?
parbox makes it block so the first row is always block aligned.
Could you please explain it more detailed or print the final source code?
thx Martin
I haven’t tested it, but I’m pretty sure I set \parbox only for the biggest item, and only for that item.
If you don’t constrain within parbox the other cells in a right-aligned tabular environment should align to the right just fine.
Hey buddy,
why not using eqparbox ? It’s precisely the kind of job it was made for…
That’s wonderful, thanks Nicolas.
I’ll make sure to post the code using
eqparboxas soon as I can!