# merge two tables into one

i have two sperate tables with the same number of rows and labels as follows:

one:

a  12
b  32
c  18


two:

a  45
b  98
c  300


how can i combine those two tables into one? as follows:

a 12 45
b 32 98
c 18 300


thank Elisheva

• Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Mar 20 '14 at 11:11
• Your question is somewhat ambiguous. Do you mean to say that the "one:" and "two:" are in external files as text, and you would like to create a LaTeX table that looks like the third example? If that were so, then something like this: tex.stackexchange.com/questions/117747/… might be useful. Mar 20 '14 at 11:22
• i have to seperate latex's file table, i am not sure that the link you gave help me, or i am worng..? Mar 20 '14 at 11:40
• @elishevaschwarz your question is still far from clear. What form are your two tables? As you show with space separated values? Or are they marked up as latex tabular already? Mar 20 '14 at 12:01
• i have to confess that i am just a bigginer.. i add Screenshot of the two files Mar 20 '14 at 12:11

The \pgfplotstablecreatecol command from the pgfplotstable package can be used here to add additional columns to a table when it is created:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
%\pgfplotsset{compat=1.10}

%the following section is just for the example; you can have your actual tables
% in separate external files
\usepackage{filecontents}
\begin{filecontents*}{table1.dat}
name data1
a  12
b  32
c  18
\end{filecontents*}
\begin{filecontents*}{table2.dat}
name data2
a  45
b  98
c  300
\end{filecontents*}
%%%% end of section %%%%%%%%%%%%%%%

\pgfplotstablecreatecol[

\begin{document}

\pgfplotstabletypeset[
string type,
every last row/.style={after row=\bottomrule}

\end{document}


As I mentioned in the code, the filecontents* section is just for the example; you can have your tables in external separate files, for example, or you can have them in your actual .tex file.

Here's a more real example, explaining step by step the procedure.

1. Create a file table1.dat like this one:

Category Valuea
{Share Jewish}  0.87
{Share Muslim}  0.05
{Share other religion}  0.08
{Mean age}  33.28
{Share born in Israel}  0.69
{Share work}  0.23
{Share male}  0.51
{Share dis\_21}  0.01
{Share dis\_18}  0.00
{Share dis\_13}  0.00

2. Create a file table2.dat like this one:

Category Valueb
{Share Jewish}  0.13
{Share Muslim}  0.51
{Share other religion}  0.18
{Mean age}  23.16
{Share born in Israel}  0.29
{Share work}  0.15
{Share male}  0.33
{Share dis\_21}  0.02
{Share dis\_18}  0.01
{Share dis\_13}  0.01


Notice that entries with more than one word are grouped using braces. Also I provided some headings for the first row of the merged table.

3. Save these files in your current working directory (the same cotaining your .tex file).

4. Your .tex file should have the following aspect:

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
%\pgfplotsset{compat=1.10}

% Create additional column for table1 containing
% second column from table2
\pgfplotstablecreatecol[

\begin{document}

% Print the merged table
\pgfplotstabletypeset[
string type,

• @elishevaschwarz It all depends on what exactly is on table1.tex and table2.tex (raw data as in the example in your question or already formatted tabulars?). Also notice that you don't use \input to include (and merge) your tables. You use the commands I described in my answer. Mar 21 '14 at 0:33