# Append columns in table from two input files

Suppose I have 2 files, in1.tex and in2.tex. In file in1.tex, the data is

1a & 1b \\
1c & 1d


and in in2.tex, the data is in a similar format:

2a & 2b \\
2c & 2d


In my scenario, these are output tables from Stata. To combine these vertically, I could just do

\input{in1.tex} \\
\input{in2.tex}


I'm wondering if there's a way I could append these two files so that they appear side by side... in other words, to get something like

1a & 1b & 2a & 2b \\
1c & 1d & 2c & 2d


EDIT: So that I can put this in a tabular/table environment.

\begin{table}[htbp]
\begin{tabular}{*{4}{c}}
** some function of in1.tex and in2.tex here
\end{tabular}
\end{table}


Thanks!

• Do in1.tex and in2.tex have the same number of rows? And, if the eventual output is supposed to be in a tabular, you don't need to mix the two before setting in in a (say) 4-column tabular. Perhaps you could be more explicit in terms of what you want as output. – Werner Jan 7 '16 at 7:03
• Yeah, let's assume that they have the same number of rows. If you could help elaborate on what you mean by your second sentence, that would be awesome. – Art Jan 7 '16 at 7:07

You don't need to merge in1.tex and in2.tex horizontally into in3.tex (say) before setting it in a tabular. Here's how you can do it without that merger:

\documentclass{article}

\usepackage{filecontents}

% First standalone table
\begin{filecontents*}{in1.tex}
1a & 1b \\
1c & 1d
\end{filecontents*}

% Second standalone table
\begin{filecontents*}{in2.tex}
2a & 2b \\
2c & 2d
\end{filecontents*}

% Third combined table
\begin{filecontents*}{in3.tex}
1a & 1b & 2a & 2b \\
1c & 1d & 2c & 2d
\end{filecontents*}

\begin{document}

% Combined in1.tex and in2.tex
\begin{tabular}[t]{ *{2}{c} }
\input{in1}%
\end{tabular}%
\begin{tabular}[t]{ *{2}{c} }
\input{in2}%
\end{tabular}

\bigskip

% Desired output
\begin{tabular}{ *{4}{c} }
\input{in3}%
\end{tabular}

\end{document}


Some things to note here:

1. Either end of the tabular structure has only half the regular \tabcolsep; that is, .5\tabcolsep. As such, a horizontal concatenation is equivalent to a regular \tabcolsep.

2. \input{..}% ends with a %. See What is the use of percent signs (%) at the end of lines?

3. End the first tabular using \end{tabular}%. Motivation similar to above.

4. The two separate tabulars are [t]op aligned. However, in the case where the numbers of rows in in1.tex and in2.tex are equal, there is no real need for this forced alignment.

• Wow. Didn't know you could do that. Thanks a lot! – Art Jan 8 '16 at 2:00