![\newwrite,pgfplotstable:将生成的行放在一起到一个 pgfplotstable(后续问题)](https://linux22.com/image/405651/%5Cnewwrite%EF%BC%8Cpgfplotstable%EF%BC%9A%E5%B0%86%E7%94%9F%E6%88%90%E7%9A%84%E8%A1%8C%E6%94%BE%E5%9C%A8%E4%B8%80%E8%B5%B7%E5%88%B0%E4%B8%80%E4%B8%AA%20pgfplotstable%EF%BC%88%E5%90%8E%E7%BB%AD%E9%97%AE%E9%A2%98%EF%BC%89.png)
我从 @egreg 那里得到一个代码,该代码在循环中创建外写文本文件中的行。
我需要将所有这些行放在 1 个 pgfplotstable 中,这意味着
\ifnum\the\filecount=1 \pgfplotstableread[col sep=comma]{data\the\filecount.txt}{\main}\else
\pgfplotstableread[col sep=comma]{data\the\filecount.txt}{\temp}
% \pgfplotstablevertcat{\main}{\temp} % <--- Does not work!
我该如何放置 pgfplotstablevertcat 命令?
请注意,对于我的主要算法,我必须将前几行的内容放入后续行中。因此,我将首次将其保留在此复杂的输出方法中。后面的主要代码可能会在以后讨论和简化。
\documentclass[a4paper]{article}
\usepackage{pgfplotstable}
\newcount\filecount
\newwrite\cisout
\begin{document}
\filecount=1
\def\aaa{file number \the\filecount}%
\loop
\immediate\openout\cisout=data\the\filecount.txt
\immediate\write\cisout{%
111, 222, \aaa
}
\immediate\closeout\cisout
\ifnum\the\filecount=1 \pgfplotstableread[col sep=comma]{data\the\filecount.txt}{\main}\else
\pgfplotstableread[col sep=comma]{data\the\filecount.txt}{\temp}
% \pgfplotstablevertcat{\main}{\temp} % <--- Does not work!
\fi
\advance\filecount by 1
\ifnum\filecount<5
\repeat
\section{The Main Table is incomplete}
\pgfplotstabletypeset[col sep=comma, string type]{\main}
\section{The last Temp-Table}
\pgfplotstabletypeset[col sep=comma, string type]{\temp}
\section{Input Test}
\input{data1.txt} \\
\input{data2.txt}\\
\input{data3.txt}\\
\input{data4.txt}
\end{document}
答案1
它的工作原理如下:
\documentclass[a4paper]{article}
\usepackage{pgfplotstable}
\pgfplotstableset{string type}
\newcount\filecount
\newwrite\cisout
\begin{document}
\filecount=1
\def\aaa{\the\filecount}%
\loop
\immediate\openout\cisout=data\the\filecount.txt
\immediate\write\cisout{%
111, 222, \aaa
}
\immediate\closeout\cisout
\ifnum\the\filecount=1 \pgfplotstableread[col sep=comma, string type]{data\the\filecount.txt}{\main}%
\else \pgfplotstableread[col sep=comma, string type]{data\the\filecount.txt}{\temp}%
\pgfplotstablevertcat{\main}{\temp}% <--- Does work!
\fi%
\advance\filecount by 1
\ifnum\filecount<5
\repeat
\section{The Main Table is incomplete}
\pgfplotstabletypeset[col sep=comma, string type]{\main}
\section{The last Temp-Table}
\pgfplotstabletypeset[col sep=comma, string type]{\temp}
\section{Input Test}
\input{data1.txt} \\
\input{data2.txt}\\
\input{data3.txt}\\
\input{data4.txt}
\end{document}