
我從 @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}