document.tex
:
\documentclass{article}
\usepackage{standalone}
\usepackage{pgfplotstable}
\begin{document}
\input{plot.tex}
\end{document}
plot.tex
:
\documentclass{standalone}
\usepackage{pgfplotstable}
\pgfplotstableread{
X Y
1 2
3 4
}\table
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot table {\table};
\end{axis}
\end{tikzpicture}
\end{document}
编译使用:
pdflatex document.tex
我得到了:
(./plot.tex
! LaTeX Error: Not in outer par mode.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.14 \addplot table {\table};
?
! Emergency stop.
...
l.14 \addplot table {\table};
! ==> Fatal error occurred, no output PDF file produced!
Transcript written on document.log.
独立文件编译得很好,只有当我尝试将其包含到另一个文档中时才会出现该错误。为什么会发生这种情况?我有什么选择?
答案1
正如 Ulrike Fischer 所说评论,解决方案是移到\pgfplotstableread
内部\begin{document}
:
\documentclass{standalone}
\usepackage{pgfplotstable}
\begin{document}
%%%%%%%%%%%%%%%%%%%
\pgfplotstableread{
X Y
1 2
3 4
}\table
%%%%%%%%%%%%%%%%%%%
\begin{tikzpicture}
\begin{axis}
\addplot table {\table};
\end{axis}
\end{tikzpicture}
\end{document}