Almost too easy:

I have two databases "First" and "Second", both get their data from tab-delineated files "First.txt" and "Second.txt"

Both contain two columns ('year' and 'number') and an equal amount of rows!

This code :


\catcode`\^^I=12 %
\DTLsetseparator{   }%





creates two separate tables, but I am trying to make a table containing three columns: year, number (from First), number (from Second).

I know it sounds trivial (and probably is)... but I am stuck.

Anyone any idea?


Here's a way of appending the second column of the second database to the first database. (I've used comma-separated values rather than tab separated for simplicity, but you can changed that as required.) This assumes that both databases have their rows in the same order (on the first column).



% generate first test database

% generate second test database



% append second column of second data base to first data base


  % iterate through each entry in the `Number' column of the second database
  \advance\rowIdx by 1\relax
  % get corresponding row of first database
  % append to current row (this new column is assigned the key `Number2')
  % update first database



The result looks like:

Image of result

  • Brilliant! Just what I hoped! (Your answer made me realise that I needed to upgrade my TexLive installation, but then I couldn't wait and so I did an install of the datatool.dtx and .ins directly.) Your solution can easily be extended to situations when I need to append more than one column. Thanks a lot Nicola!
    – brvbogae
    Jun 5 '13 at 17:47

This uses the readarray package to input the datafiles into "array" data structures (here named first and second). Then those array elements can be regurgitated in the table. The only quirk, for which I used a solution based on that provided by Herbert in How to programmatically make tabular rows using `\whiledo` ?, is that the \whiledo used to construct each row of the table has to be performed outside of the tabular environment. In particular, it is the presence of tab characters & inside the \whiledo inside the tabular that is somehow the problem (resolved by Herbert).

  % Based on:
  % https://tex.stackexchange.com/questions/7590/
  % how-to-programmatically-make-tabular-rows-using-whiledo
\whiledo{\value{index} < \nrows}{%
    \arrayij{first}{\thetabindex}{1} &
    \arrayij{first}{\thetabindex}{2} &

enter image description here

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.