有没有办法将文件路径前缀(最好由键定义)添加到 的“参数”中\addplot table
。例如
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{%
table file path/.initial = {./}}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\pgfplotsset{%
table file path = {./cvsfile/}}
% Plot ./cvsfile/myfile
\addplot table {myfile};
\end{axis}
\end{tikzpicture}
\end{document}
答案1
这似乎有效......
\documentclass{standalone}
\usepackage{pgfplots}
\makeatletter
\def\pgfplotstableread@openfile{%
\def\pgfplotstable@loc@TMPa{\pgfutil@in@{ }}%
\expandafter\pgfplotstable@loc@TMPa\expandafter{\pgfplotstableread@filename}%
\ifpgfutil@in@
\t@pgfplots@toka=\expandafter{\pgfplotstableread@filename}%
\edef\pgfplotstableread@filename{\pgfplots@dquote\the\t@pgfplots@toka\pgfplots@dquote}%
\fi
\let\pgfplotstableread@old@crcr=\\%
\def\\{\string\\}% just to make sure we don't try to open inline table data...
\openin\r@pgfplots@reada=\csname pgfk@/pgfplots/table file path\endcsname\[email protected]
\ifeof\r@pgfplots@reada
\openin\r@pgfplots@reada=\csname pgfk@/pgfplots/table file path\endcsname\pgfplotstableread@filename\relax
\else
\pgfplots@warning{%
You requested to open table '\pgfplotstableread@filename', but there is also a '\[email protected]'.
TeX will automatically append the suffix '.tex', so I will now open '\[email protected]'.
Please make sure you don't accidentally load TeX files - this may produce unrecoverable errors.}%
\closein\r@pgfplots@reada
\openin\r@pgfplots@reada=\pgfplotstableread@filename\relax
\fi
%
\ifeof\r@pgfplots@reada
\pgfplotsthrow{no such table file}{\pgfplots@loc@TMPa}{\pgfplotstableread@filename}{Could not read table file '\csname pgfk@/pgfplots/table file path\endcsname\pgfplotstableread@filename'. In case you intended to provide inline data: maybe TeX screwed up your end-of-lines? Try `row sep=crcr' and terminate your lines with `\string\\' (refer to the pgfplotstable manual for details)}\pgfeov%
\global\let\pgfplotstable@colnames@glob=\pgfplots@loc@TMPa
\def\pgfplotstableread@ready{0}%
\fi
\pgfplots@logfileopen{\pgfplotstableread@filename}%
\let\\=\pgfplotstableread@old@crcr
}
\makeatother
\pgfplotsset{%
table file path/.initial = {./}}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\pgfplotsset{%
table file path = {./cvsfile/}
}
% Plot ./cvsfile/myfile
\addplot table {myfile2.txt};
\end{axis}
\end{tikzpicture}
\end{document}