# Boolean variables in LaTeX

I am trying to use "boolean" variables in LaTeX but am unable to have any success...

I have a macro which takes 5 arguments, the last argument being optional. This macro is named educationItem and it only ever appears in an education environment. So, some educationItem entries will have this fifth argument, and some will not. The ones that have the fifth argument will require a slightly modified formatting.

In addition, I would like the ability to disable this fifth argument for all educationItem entries, such that it appears as if all educationItem entries have no fifth argument. In order to do this, I am currently using an option passed when including my cvtools.sty file.

My current attempt (shown below) does not seem to work and stuffs up the table alignment. I think that it may be due to the time at which the various expressions are evaluated, but have not been able to fix it.

Any help would be appreciated.

A minimum working example follows:

main.tex:

\documentclass[10pt]{article}

\usepackage{cvtools} % my CV styling stuff
\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}
{
}
\end{education}

\end{document}


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
%================================================%

\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}
% \end{education}
%================================================%
\newenvironment{education}%
{%
\def\lwidth{0.16\textwidth}%
\def\rwidth{0.78\textwidth}%
%
%
\newcommand\educationItem[5]{%
% Check if we should display tools
\ifstrempty{##5}%
{% showGrades is true, but this \educationItem has no grades to display.
\def\@numRows{1}%
}%
\def\@numRows{2}%
}%
\else
\def\@numRows{1}%
\fi
%
% Education period
\multirow{\@numRows}{\lwidth}{##1 -- ##2}%
%
% Name and institution
& \textbf{##3 (##4)}%
%
{%
\\* %
& \begin{tabularx}{\rwidth}{Xr} %
##5 %
\end{tabularx} %
}%
{}%
\\[0.5em]%
}%
%
\begin{longtable}{L{\lwidth}!{\VRule}R{\rwidth}}%
}
{\end{longtable}}
%------------------------------------------------%


The expected output would be identical to the following TeX code... when using \usepackage[showgrades]{cvtools}:

\documentclass[10pt]{article}

\usepackage[margin=3cm]{geometry}   % extend page margins
\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

%================================================%
% 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{document}

\section*{Education}
% \begin{education}
\def\lwidth{0.16\textwidth}
\def\rwidth{0.78\textwidth}
\begin{longtable}{L{\lwidth}!{\VRule}R{\rwidth}}

% \educationItem{2008}{2012}
% {Education 1}
% {University 1}
% {}
\multirow{1}{\lwidth}{2008 -- 2012}
& \textbf{Education 1 (University 1)}%
% @shouldshowgrades should be false here
\\[0.5em]

% \educationItem{2002}{2007}
% {Education 2}
% {University 2}
% {
% ...
% }
\multirow{1}{\lwidth}{2002 -- 2007}
& \textbf{Education 2 (University 2)}%
% @shouldshowgrades should be true here
\\*
& \begin{tabularx}{\rwidth}{Xr} %
Subject 1 & 90/100 \\
Subject 2 & 88/100 \\
Subject 3 & 97/100 \\
Subject 4 & 94/100 \\
Subject 5 & 95/100 \\
\end{tabularx}
\\[0.5em]

% \end{education}
\end{longtable}

\end{document}


When using \usepackage{cvtools}:

\documentclass[10pt]{article}

\usepackage[margin=3cm]{geometry}   % extend page margins
\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

%================================================%
% 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{document}

\section*{Education}
% \begin{education}
\def\lwidth{0.16\textwidth}
\def\rwidth{0.78\textwidth}
\begin{longtable}{L{\lwidth}!{\VRule}R{\rwidth}}

% \educationItem{2008}{2012}
% {Education 1}
% {University 1}
% {}
\multirow{1}{\lwidth}{2008 -- 2012}
& \textbf{Education 1 (University 1)}%
% @shouldshowgrades should be false here
\\[0.5em]

% \educationItem{2002}{2007}
% {Education 2}
% {University 2}
% {
% }
\multirow{1}{\lwidth}{2002 -- 2007}
& \textbf{Education 2 (University 2)}%
% @shouldshowgrades should be true here
\\[0.5em]

% \end{education}
\end{longtable}

\end{document}

-
Can you provide what the expected output is. – Peter Grill Jul 17 '12 at 4:23
@PeterGrill - added LaTeX code that would produce identical expected output – Joshua Spence Jul 17 '12 at 4:53
Follow up question: Misalignment of table columns when using multirow. – Peter Grill Jul 18 '12 at 21:26

The following with \usepackage[showgrades]{cvtools} produces:

or with \usepackage{cvtools}:

## Changes:

• Added package option to \usepackage[showgrades]{cvtools} so that showgrades was enabled.
• Few spurious spaces eliminated by adding a % (noted in code).
• You were missing a \ in:

\ifthenelse{\equal{\@shouldshowgrades}{1}}

• Changed \def to \gdef so that those settings are available when needed.

• Eliminated the \multirow for displaying the years.

## Code:

\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
%================================================%

\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}
% \end{education}
%================================================%
\newenvironment{education}%
{%
\def\lwidth{0.16\textwidth}%
\def\rwidth{0.78\textwidth}%
%
%
\newcommand\educationItem[5]{%
% Check if we should display tools
\ifstrempty{##5}%
{% showGrades is true, but this \educationItem has no grades to display.
\gdef\@numRows{1}%
}%
\gdef\@numRows{2}%
}%
\else%
\gdef\@numRows{1}%
\fi%
%
% Education period
%\multirow{\@numRows}{\lwidth}{##1 -- ##2}%
##1 -- ##2% <-- Eliminated \multirow

%
% Name and institution
& \textbf{##3 (##4)}%
%
{%
\\*%
& \begin{tabularx}{\rwidth}{Xr}%
##5%
\end{tabularx}%
}%
{}%
\\[0.5em]%
}%
%
\begin{longtable}{L{\lwidth}!{\VRule}R{\rwidth}}%
}%
{\end{longtable}}%
\end{filecontents*}

\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}%
{%

 Great! Thanks Peter. However, I would like to use the multirow there... the reason is that I do a similar thing in another environment with longer text in the left column. Without multirow the second row is shifted down to make room for the text in the upper left cell... hence why the multirow is required. Why is it that doing it your way (but using the multirow), the left and right columns become out of alignment? – Joshua Spence Jul 18 '12 at 3:36 @JoshuaSpence: I am not sure what is going on with the \multirow. I would suggest posting a follow up question specifically for the \multirow issue, with this MWE as it is already packaged, and reference that that is a follow up to this question. – Peter Grill Jul 18 '12 at 4:39 Good idea. Thanks – Joshua Spence Jul 18 '12 at 5:42