16

I have two very short and consecutive sections (for a CV), each containing a small table:

\section{Work Experience}

\begin{tabular}{r|p{11cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}\ 
\end{tabular}

\section{Education}

\begin{tabular}{r|p{11cm}}
Slightly wider first column & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\multicolumn{2}{c}{}\ 
\end{tabular}

So each table has two columns: The first containing the period, aligned to the right. The second: some more info with a certain width, top (and left) aligned.

The problem is that the width of the left column in the two tables is different, and doesn't look nice since the sections (therefore tables) are consecutive and in one page. I cannot give r a width like p:

\begin{tabular}{r{11cm}|p{11cm}}

Does not work. How can I get the widths of the first columns of the two tables the same length while also having them right aligned?

EDIT Thanks for the answers, they all work for me so I upvoted all of them, and accepted the one that appealed to me the most (and most upvoted), since you don't have to specify the \hfill in each row. However if you don't want to use the array package for any reason then the other solutions are also great.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
vahidg
  • 3,953
  • 2
  • 22
  • 30
  • 1
    Not an answer to you questions as such, but I use the currvita package to maintain my CV (well, with suitable hacks...): http://www.ctan.org/tex-archive/macros/latex/contrib/currvita/ . That way *you* don't have to deal with these details. – dmckee --- ex-moderator kitten Feb 19 '10 at 22:42
  • Thanks for the tip, well check it out for the next version :) – vahidg Feb 21 '10 at 20:44

5 Answers5

17

If you use the array package, you can put the \hfill in the header as follows, so you don't have to remember to put it (or a \parbox) in each row.

\documentclass{article}
\usepackage{multicol}
\usepackage{array}
\begin{document}
\section{Work Experience}

\begin{tabular}{>{\hfill}p{5cm}|p{11cm}}
  Current & Your job at Your Company, Town \\
  Jan 2009 & What your company does \\
  & A description of what you do\\
  \multicolumn{2}{c}{} 
\end{tabular}

\section{Education}

\begin{tabular}{>{\hfill}p{5cm}|p{11cm}}
  Slightly wider first column & University, Town \\
  Jan 2009 & Thesis subject \\
  & A description of what you did\\
  \multicolumn{2}{c}{} 
\end{tabular}
\end{document}

to give:

alt text http://www.freeimagehosting.net/uploads/5e29f675e3.jpg

Ramashalanka
  • 8,564
  • 1
  • 35
  • 46
6

Here's a variant of @RTBarnard's answer using the tabularx package:

\documentclass[a4paper,twoside,draft,12pt]{article}
\usepackage{tabularx}
\begin{document}

\section{Work Experience}

\begin{tabularx}{\textwidth}{>{\raggedleft}X|p{8cm}}
Current & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\end{tabularx}

\section{Education}

\begin{tabularx}{\textwidth}{>{\raggedleft}X|p{8cm}}
Somewhat wider than first column, 
overflowing into additional lines & University, Town \\
Jan 2009 & Thesis subject \\
& A description of what you did\\
\end{tabularx}
\end{document}

Notes:

  1. Why tabularx? Because it's often easier to know the width you have available for the whole table, and to let TeX calculate the unknown column widths.
  2. The first parameter is the overall table width. Here, I've specified \textwidth to fill the width of typeblock, but you can change that to whatever measure you need.
  3. I've used \raggedright rather than \hfill: if the item flows onto a second line, \hfill will only right-align the first line of the paragraph.
  4. Was the \multicol significant? I've removed it to keep the answer as simple as possible.

Run with XeTeX under TeXLive.

Brent.Longborough
  • 9,567
  • 10
  • 42
  • 62
  • 1
    For completion, i would note that if you wanna put that spec on the last column, you need to reset the meaning of "\\" using `\arraybackslash`. – Johannes Schaub - litb Feb 22 '10 at 10:12
  • Hey, didn't know that, could you elaborate? – Brent.Longborough Feb 22 '10 at 11:04
  • 1
    `\raggedleft` changes the meaning of `\\ ` to do various magic stuffs. See `{\ttfamily\meaning\raggedleft}`. `\arraybackslash` will change its meaning back to that of the tabular environment. These changes affect only the current group, so you will see compile errors only in the last column. – Johannes Schaub - litb Feb 22 '10 at 14:14
3

Here's one solution of many possibilities:

\begin{tabular}{r|p{11cm}}
\parbox{11cm}{\hfill Current} & Your job at Your Company, Town \\
Jan 2009 & What your company does \\
& A description of what you do\\
\multicolumn{2}{c}{}\ 
\end{tabular}

Basically, create a \parbox with the desired width and put an \hfill at the left.

RTBarnard
  • 4,374
  • 27
  • 27
1

You can give both p{width} options, and start each cell in the left with an \hfill.

Charles Stewart
  • 11,661
  • 4
  • 46
  • 85
1

You can use array package to specify a fill command for each row in your first column:

\begin{tabular}{>{\hfill}p{11cm}|p{11cm}|}

For example:

\documentclass{article}
\usepackage{array}
\begin{document}

\begin{tabular}{>{\hfill}p{5cm}|p{11cm}|}
This is a test & test
\end{tabular}

\begin{tabular}{>{\hfill}p{5cm}|p{11cm}|}
Test & this is a test
\end{tabular}
\end{document}
Alok Singhal
  • 93,253
  • 21
  • 125
  • 158