Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a LaTeX document in which I am using custom environment and commands to make everything a bit easier. However, when I use the multirow command in one of my custom environments, the alignment of the left and right table columns is muddled (see below).

Example of table column misalignment

A minimum working example follows. Note that, in the case shown above, a multirow isn't required. However, there are other situations where the text in the left column is longer than a single table cell from the left column, and hence the multirow is required to prevent the contents of the right column from being spaced further apart.

\documentclass[10pt]{article}

\usepackage{filecontents}
\begin{filecontents*}{cvtools.sty}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{cvtools}[2012/07/16 v1.0.0]

\RequirePackage{etoolbox}           % for \ifstrempty, \ifdef
\RequirePackage{ifthen}             % for \ifthenelse
\RequirePackage{longtable}          % for tables that span more than one page
\RequirePackage{multirow}           % for table columns that span more than one row
\RequirePackage{tabularx}           % for simple column stretching
\RequirePackage{xcolor}             % for colours

%================================================%
% Declare options
%================================================%
\newif\if@showgrades

\DeclareOption{showgrades}{\@showgradestrue}
\DeclareOption*{\PackageWarning{cvtools}{Unknown option `\CurrentOption'}}

\ProcessOptions

%================================================%
% For table styling
%================================================%
\definecolor{lightgray}{gray}{0.8}%
\newcolumntype{L}[1]{>{\raggedleft}p{#1}}%
\newcolumntype{R}[1]{p{#1}}%
\newcommand\VRule{\color{lightgray}\vrule width 0.5pt}%
%------------------------------------------------%

%================================================%
% \begin{education}
% \educationItem{beginYear}{endYear}{name}{institution}{\educationGrade{subject}{grade} ...}
% \end{education}
%================================================%
\newenvironment{education}%
{%
\def\lwidth{0.16\textwidth}%
\def\rwidth{0.78\textwidth}%
%
\newcommand\educationGrade[2]{##1 & ##2\\}%
%
\newcommand\educationItem[5]{%
% Check if we should display tools
\if@showgrades%
    \ifstrempty{##5}%
        {% showGrades is true, but this \educationItem has no grades to display.
            \gdef\@numRows{1}%
            \gdef\@shouldshowgrades{0}%
        }%
        {% showGrades is true and this \educationItem has grades to display.
            \gdef\@numRows{2}%
            \gdef\@shouldshowgrades{1}%
        }%
\else%
    % showGrades is false.
    \gdef\@numRows{1}%
    \gdef\@shouldshowgrades{0}%
\fi%
%
% Education period
\multirow{\@numRows}{\lwidth}{##1 -- ##2}%
%
% Name and institution
& \textbf{##3 (##4)}%
%
% Grades
\ifthenelse{\equal{\@shouldshowgrades}{1}}%
    {%
        \\*%
        & \begin{tabularx}{\rwidth}{Xr}%
        ##5%
        \end{tabularx}%
    }%
    {}%
\\[0.5em]%
}%
%
\begin{longtable}{L{\lwidth}!{\VRule}R{\rwidth}}%
}%
{\end{longtable}}%
\end{filecontents*}


\usepackage[showgrades]{cvtools}%
\usepackage[margin=3cm]{geometry}   % extend page margins

\begin{document}
\section*{Education}
\begin{education}
    \educationItem{2008}{2012}
    {Education 1}
    {University 1}
    {}

    \educationItem{2002}{2007}
    {Education 2}
    {University 2}
    {
    \educationGrade{Subject 1}{90/100}
    \educationGrade{Subject 2}{88/100}
    \educationGrade{Subject 3}{97/100}
    \educationGrade{Subject 4}{94/100}
    \educationGrade{Subject 5}{95/100}
    }

    \educationItem{January 2002}{December 2007}
    {Education 3}
    {University 3}
    {
    \educationGrade{Subject 1}{90/100}
    \educationGrade{Subject 2}{88/100}
    \educationGrade{Subject 3}{97/100}
    \educationGrade{Subject 4}{94/100}
    \educationGrade{Subject 5}{95/100}
    }
\end{education}
\end{document}

The third \educationItem demonstrates a longer entry which (I believe) justifies the use of multirow... without multirow I get something like this (note the undesired whitespace between "Education 3" and "Subject 1":

Example of a wide left column.

Any assistance would be greatly appreciated.

share|improve this question
    
I'm not sure what the effect you're trying to achieve is. Could you explain a little more what you mean about the column being "muddled" –  Seamus Jul 18 '12 at 9:04
    
Why not showing one of those longer entries that would make necessary multirow? In my experience almost every usage of \multirow is unnecessary (there are other solutions, usually). –  egreg Jul 18 '12 at 9:30
    
@Seamus Look at the image that I posted. The "2002-2007" on the left is not vertically aligned with the contents of the right column. –  Joshua Spence Jul 18 '12 at 12:21
    
@egreg I added an example of why I believe I need multirow –  Joshua Spence Jul 18 '12 at 12:28
    
@JoshuaSpence It's aligned with Education 3… What do you want it to align to? Subject 1? –  Seamus Jul 18 '12 at 12:51

1 Answer 1

up vote 2 down vote accepted

Just replace

\multirow{\@numRows}{\lwidth}{##1 -- ##2}%

with

\smash{\parbox[t]{\lwidth}{\raggedright ##1 -- ##2}}%

so that this entry won't contribute to the row height. It may be a problem when the right part is shorter than the left part, but I don't think it can really happen. In that case add dummy \educationGrade{}{} items.


Note. It's quite hard to understand why you're putting the definitions of \educationItemand \educationGrade in the body of the definition of education.

share|improve this answer
    
Thanks, great... I agree that the \educationGrade definition shouldn't be where it currently is. I suppose I really want it to be nested within the \educationItem command, but could not get this to work. –  Joshua Spence Jul 18 '12 at 22:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.