1

The following example code is slightly adapted from Peter Grill's answer to "Table including rows of a master table".

The problem I'm having is that if I have a multirow, then I need an extra blank line immediately after it. If I'm selecting an arbitary subset of rows, this is hard to do automatically. I thought I could add the blank line (something like &&&&&&&\\) to the csv file at the end of the multirow line, but datatool does not like it. Any other ideas?

\documentclass{article}
\usepackage{array}
\usepackage{multirow}
\usepackage{datatool}
\usepackage{filecontents}
\newcommand{\colhead}[1]{\multicolumn{1}{>{\bfseries}l}{#1}}
\newcounter{tabenum}\setcounter{tabenum}{0}
\newcommand{\nextnuml}[1]{\refstepcounter{tabenum}\thetabenum.\label{#1}}

\begin{filecontents*}{foo.dat}
  Hammer001,   Hammer,    1 ,  0 , 1 , 10 , 1 , \multirow{2}{2in}{light (add some words here to wrap around)}\\
  Hammer002,   Hammer,    2 ,  0 , 1 , 10 , 1 , heavy\\
  Hammer003,   Hammer,    3 ,  0 , 1 , 10 , 1 , really heavy\\
  Longsword001,Longsword, 1 , -1 , 2 , 75 , 2 , one-handed \\
  Longsword002,Longsword, 2 , -1 , 2 , 75 , 2 , two-handed \\
  Longsword003,Longsword, 3 , -1 , 2 , 75 , 2 , three-handed \\
\end{filecontents*}

\newcommand{\PrintDTLTable}[2]{%
  % #1 = database to search
  % #2 = list of rowIDs
  \begin{tabular}{c c c c c c c p{3.0cm}}
   & \colhead{Label} & \colhead{Cost} & \colhead{Weight} & \colhead{PropA} & \colhead{PropB} & \colhead{PropC} & \colhead{Description}\\\hline
    \DTLforeach[\DTLisSubString{#2}{\RowID}]{#1}{%
      \RowID=RowID,%
      \Label=Label,%
      \Cost=Cost,%
      \Weight=Weight,%
      \PropA=PropA,%
      \PropB=PropB,%
      \PropC=PropC,%
      \Description=Description%
    }{%
      \nextnuml{\RowID} & \Label &\Cost & \Weight & \PropA & \PropB & \PropC & \Description
    }%
  \end{tabular}
}%

\begin{document}
% \DTLsetseparator{&}% Define separator of the data
\DTLloaddb[noheader,keys={RowID,Label,Cost,Weight,PropA,PropB,PropC,Description}]{myDB}{foo.dat}

% \DTLdisplaydb{myDB}% Usefule for debugging.

\PrintDTLTable{myDB}{Hammer001,Hammer003,Longsword003}

This is a reference to ~\ref{Hammer003}.

\end{document}
1

Actually, the following seems to work. Define

\newcommand{\foo}{&&&&&&&}

Then add \foo to the end of the multirow line. So, whenever the multirow line is included, so is the extra blank line. Does anyone see a problem with this? If you think of a better, more elegant way, please post. For some reason, adding &&&&&&& directly to the csv file gives an error; I'm not sure why. Since I don't really understand how datatool works, an explanation would be appreciated.

Hammer001,   Hammer,    1 ,  0 , 1 , 10 , 1 , \multirow{2}{2in}{light (add some words here to wrap around)}\\ \foo \\

ADDENDUM: Actually, it is even simpler. \foo is not needed. One can just do

Hammer001,   Hammer,    1 ,  0 , 1 , 10 , 1 , \multirow{2}{2in}{light (add some words here to wrap around)}\\ \\

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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