我想从单独的文件中读取/输入表的主体。但它失败了。我该怎么做。下面是一个例子
主 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}
Run Code Online (Sandbox Code Playgroud)
表体文件:table.tex
%table.tex
\hline
a & b \\
\hline
c & d \\
\hline
Run Code Online (Sandbox Code Playgroud)
table.tex在处理它之前在宏中捕获表内容tabular。为此,请使用catchfile包:

%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}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6271 次 |
| 最近记录: |