# How to make a table with variable rows

This is my code extracted from a custom class file.

\makeatletter
\let\@tmemi\@empty\let\@tmemii\@empty
\def\tmemi#1{\gdef\@tmemi{#1}}
\def\tmemii#1{\gdef\@tmemii{#1}}

\newcommand{\tablex}{%
\begin{tabular}{r@{ : }ll}
Paticipant         & John Doe  &   Mr.      \\[1ex]
Consultant         & A. Prof   &   PhD      \\[1ex]
\ifx\@tmemi\empty  &           &
\else Team         & \@tmemi   & Manager\fi \\[1ex]
\ifx\@tmemii\empty &           &
\else              & \@tmemii  & Oganizer\fi
\end{tabular}
}
\makeatother

% Case 1
\tmemi{B. Member}
\tmemii{C. Member}
\tablex

% Case 2
\tmemi{}
\tmemii{}
\tablex


and my result and question are shown in the image below (to simplify, I only show member parameters.)

-
Do you still want the two rows of space, just the colons removed? –  Werner Aug 26 '13 at 18:35
Please always post complete documents, not just fragments. –  David Carlisle Aug 26 '13 at 19:49
To both Werner and David: Actually, no phantom blank rows, making it shorter in length. The way I coded leads to ambiguity -- my fault. –  Jesse Aug 27 '13 at 1:20

after

{r@{ : }ll}


The : is attached to the first column so to make a cell without the : you need

\multicolumn{1}{r}{}&&


so that the first cell uses r rather than r@{ : }

If you want to omit the entire row in the empty cases then:

\documentclass{article}
\usepackage{blindtext}

\begin{document}

\makeatletter
\let\@tmemi\@empty\let\@tmemii\@empty
\def\tmemi#1{\gdef\@tmemi{#1}}
\def\tmemii#1{\gdef\@tmemii{#1}}

\newcommand{\tablex}{%
\begin{tabular}{r@{ : }ll}
Paticipant         & John Doe  &   Mr.      \\[1ex]
Consultant         & A. Prof   &   PhD
\ifx\@tmemi\empty\expandafter\@gobble
\else\expandafter\@firstofone
\fi
{\\[1ex] Team         & \@tmemi   & Manager}
\ifx\@tmemii\empty\expandafter\@gobble
\else\expandafter\@firstofone
\fi
{\\[1ex]         & \@tmemii  & Oganizer}
\end{tabular}
}
\makeatother

% Case 1
\tmemi{B. Member}
\tmemii{C. Member}
\tablex

\bigskip
\hrule
\bigskip

% Case 2
\tmemi{}
\tmemii{}
\tablex

\end{document}

-
much better. But do you have an idea how to not write a row at all. Still getting blank "phantom" rows. –  LaRiFaRi Aug 26 '13 at 18:58
@LaRiFaRi oh you don't want the vertical space? that wasn't clear, in that case just include the \\  in the conditional part –  David Carlisle Aug 26 '13 at 19:43
@LaRiFaRi see update –  David Carlisle Aug 26 '13 at 20:00

The following compartmentalizes the output to manage the portions a bit better:

\documentclass{article}

\makeatletter
\newcommand{\@printtmemi}{Team & \@tmemi  & Manager}
\newcommand{\@printtmemii}{    & \@tmemii & Organizer}
\newcommand{\@nextline}{\\[1ex]}
\def\@emptytmem{}
\let\@tmemi\@emptytmem\let\@tmemii\@emptytmem
\def\tmemi#1{\gdef\@tmemi{#1}}
\def\tmemii#1{\gdef\@tmemii{#1}}

\newcommand{\tablex}{%
\begin{tabular}{r@{ : }ll}
Paticipant             & John Doe  &   Mr.  \@nextline
Consultant             & A.\ Prof  &   PhD
\setbox8=\hbox{\@tmemi}\ifdim\wd8>\z@%
\@nextline\@printtmemi\fi
\setbox8=\hbox{\@tmemii}\ifdim\wd8>\z@%
\@nextline\@printtmemii\fi
\end{tabular}
}
\makeatother

\begin{document}

% Case 1
\tmemi{B.\ Member}
\tmemii{C.\ Member}
\tablex

\bigskip

% Case 2
\tmemi{}
\tmemii{}
\tablex

\bigskip

% Case 3
\tmemi{D.\ Member}
\tmemii{}
\tablex

\end{document}

-