Graphics, Figures & TablesFunction To Produce Table If Row Not Blank

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
EFaden
Posts: 24
Joined: Thu Jun 04, 2009 2:58 am

Function To Produce Table If Row Not Blank

Post by EFaden »

So I am trying to make a function that takes 14 arguments. Basically it is going to create a tabular that has rows IFF the variable for that row is non empty. Below is a MWE of what I have so far. It has two issues... issue 1 is that if the last rows are empty it still produces little vert lines... issue 2 is that using the hack to let me get more than 14 arguments doesn't seem to work with the equal function and those rows are always present even if empty... thoughts?

Code: Select all

%% Document Class
\documentclass[11pt,english]{article}
    
%% AMS-Tex Packages, LatexSym, and FC
\usepackage{amssymb, amsmath, amsthm, amstext}
\usepackage{latexsym}

%$ If Then
\usepackage{xifthen}

\begin{document}
	\def\LongFunction#1#2#3#4#5#6#7#8#9{%
		\def\ArgI{{#1}}%
		\def\ArgII{{#2}}%
		\def\ArgIII{{#3}}%
		\def\ArgIV{{#4}}%
		\def\ArgV{{#5}}%
		\def\ArgVI{{#6}}%
		\def\ArgVII{{#7}}%
		\def\ArgVIII{{#8}}%
		\def\ArgIX{{#9}}%
		\LongFunctionRelay
	}	

	\def\LongFunctionRelay#1#2#3#4#5{%
		\begin{table}
		\begin{tabular}{| p{.75in} | p{3.75in} | }
		\hline
		\ifthenelse{\equal{\ArgI}{}}{}{Row 1 & \emph{\ArgI} \\ \hline}
		\ifthenelse{\equal{\ArgII}{}}{}{Row 2 & \ArgII \\ \hline}
		\ifthenelse{\equal{\ArgIII}{}}{}{Row 3 & \ArgIII \\ \hline}
		\ifthenelse{\equal{\ArgIV}{}}{}{Row 4 & \ArgIV \\ \hline}
		\ifthenelse{\equal{\ArgV}{}}{}{Row 5 & \ArgV \\ \hline}
		\ifthenelse{\equal{\ArgVI}{}}{}{Row 6 & \ArgVI \\ \hline}
		\ifthenelse{\equal{\ArgVII}{}}{}{Row 7 & \ArgVII \\ \hline}
		\ifthenelse{\equal{\ArgVIII}{}}{}{Row 8 & \ArgVIII \\ \hline}
		\ifthenelse{\equal{\ArgIX}{}}{}{Row 9 & \ArgIX \\ \hline}
		\ifthenelse{\equal{#1}{}}{}{Row 10 & #1 \\ \hline}
		\ifthenelse{\equal{#2}{}}{}{Row 11 & #2 \\ \hline}
		\ifthenelse{\equal{#3}{}}{}{Row 12 & #3 \\ \hline}
		\ifthenelse{\equal{#4}{}}{}{Row 13 & #4 \\ \hline}
		\ifthenelse{\equal{#5}{}}{}{Row 14 & #5 \\ \hline}
	\end{tabular}
	\end{table}
	}
	
	\LongFunction{1}{2}{3}{4}{5}{6}{7}{8}{9}{10}{11}{12}{13}{14}
	\LongFunction{1}{2}{3}{}{}{}{}{}{}{}{}{}{}{}
\end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

5gon12eder
Posts: 126
Joined: Sun Feb 13, 2011 8:36 pm

Function To Produce Table If Row Not Blank

Post by 5gon12eder »

I didn't went through your problem in detail and I don't know what you need this for but in general, using one of the key-value-approaches is much more convenient and instructive for functions with that many arguments. If you find it helpful, have a look at the attachment. It's a single-purpose-package I've written once for a quite similar problem using the keyval package. Note that it doesn't rely on any low-level hacking.

Best
Attachments
imagedescription.sty
(5.74 KiB) Downloaded 212 times
I'm using pdfTeX, Version 3.1415926-1.40.10 (TeX Live 2009/Debian).
EFaden
Posts: 24
Joined: Thu Jun 04, 2009 2:58 am

Re: Function To Produce Table If Row Not Blank

Post by EFaden »

I could try that. That still doesn't entirely solve the last row issue. Any thoughts as to why I would be getting two vert lines on the bottom of the table? It seems like it is seeing the if statement and putting the dividers despite having no resulting content from the if statement.
Post Reply