我想\input{...}
在新环境中使用该命令,然后在表格环境中使用该命令。我想包含的文件包含&
并\\
格式化表格。如果我使用单个命令或\<EnvironmentName>\end<EnvironmentName>
makros,一切都会正常工作。但\begin{...}\end{...}
结果却出现错误...
怎么办?为什么?我不明白 :(
\documentclass{article}
\usepackage{filecontents}
%
%
\begin{filecontents}{in0.tex}
a
\end{filecontents}
%
\begin{filecontents}{in1.tex}
a\\
b
\end{filecontents}
%
\begin{filecontents}{in2.tex}
a & b
\end{filecontents}
%
%
\newcommand{\myinputcmd}[1]{\input{in#1}}
\newenvironment{myinputenv}[1]{\input{in#1}}{}
%
%
%
\begin{document}
%
% use command
\begin{tabular}{c}
\myinputcmd{0} % works
\end{tabular}
\begin{tabular}{c}
\myinputcmd{1} % works
\end{tabular}
\begin{tabular}{cc}
\myinputcmd{2} % works
\end{tabular}
%
% use \environmen\endenvironment
\begin{tabular}{c}
\myinputenv0\endmyinputenv % works
\end{tabular}
\begin{tabular}{c}
\myinputenv1\endmyinputenv % works
\end{tabular}
\begin{tabular}{cc}
\myinputenv2\endmyinputenv % works
\end{tabular}
%
% use \begin{environmen}\end{environment}
\begin{tabular}{c}
\begin{myinputenv}{0}\end{myinputenv} % works
\end{tabular}
\begin{tabular}{c}
\begin{myinputenv}{1}\end{myinputenv} % error: \begin{tabular} ended by \end{myinputenv} (and others)
\end{tabular}
\begin{tabular}{cc}
\begin{myinputenv}{2}\end{myinputenv} % error: \begin{tabular} ended by \end{myinputenv} (and others)
\end{tabular}
%
\end{document}