2014-10-06 49 views
1

我想從單獨的文件中讀取/輸入表格的主體。 但它失敗了。 我該怎麼做。 的下面是一個例子如何從單獨的文件中讀取表格的主體?

主要tex的文件: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.tex

%table.tex 
\hline 
a & b \\ 
\hline 
c & d \\ 
\hline 
+1

歡迎的StackOverflow! (La)最好在[tex.se]問TeX相關的問題。您的問題已被標記,以便在那裏遷移。 – 2014-10-06 08:27:23

回答

1

捕獲表的內容中table.tex在宏在處理它之前在tabular。爲此,使用catchfile package

enter image description here

%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} 
+0

非常感謝。那只是我想要的。 – 2014-10-07 00:30:47

相關問題