I want to read/input the body of a table from a separate file. But it failed. How can I do it. The below is an example
Main tex file: Main.tex
%main.tex
\documentclass{article}
\begin{document}
Table test.
1. Insert a full table
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
c & d \\
\hline
\end{tabular}
2. Input the body of table from a seperate file
\begin{tabular}{|c|c|}
\input{table}
\end{tabular}
\end{document}
Table body file: table.tex
%table.tex
\hline
a & b \\
\hline
c & d \\
\hline
Capture the table contents in table.tex
in a macro before processing it inside a tabular
. For this, use the catchfile
package:
%main.tex
\documentclass{article}
\usepackage{filecontents,catchfile}
\begin{filecontents*}{table.tex}
%table.tex
\hline
a & b \\
\hline
c & d \\
\hline
\end{filecontents*}
\begin{document}
Table test.
1. Insert a full table
\begin{tabular}{|c|c|}
\hline
a & b \\
\hline
c & d \\
\hline
\end{tabular}
2. Input the body of table from a seperate file
\CatchFileDef{\mytable}{table.tex}{}% table.tex > \mytable
\begin{tabular}{|c|c|}
\mytable
\end{tabular}
\end{document}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With