
この掲示板の推奨により、ラボ レポートで pgfplotstable を使用して CSV からデータをインポートし、LaTeX で表として印刷することにしました。ただし、付録などのセクションでは、表を見出しの下 (見出しの上ではなく) に配置する必要があるため、コード内に配置した場所に LaTeX で表を配置するにはどうすればよいでしょうか。
サンプル:
\appendix
\appendixpage
\section{Tables}
\begin{subappendices}
\subsection{Heading 1}
\pgfplotstableread{mydata.csv}{\mydatalabel}
\begin{table}
\centering
\caption[LoT Caption]{Full Caption}
\pgfplotstabletypeset[%
every head row/.style={
before row=\toprule, after row=\midrule},
every last row/.style={
after row=\bottomrule},
]{\mydatalabel}
\label{table:mydatalabel}
\end{table}
LaTeX は自動的にフォーマットし、表を見出し 1 (および他の見出しも) の上に配置します。
pgfplotstables を使用する前は、テーブルを意図した場所に強制的に配置するために次のコードを使用していました。
\begin{center}
\captionof{table}[LoT Caption]{Full Caption}
\begin{tabular}{c c c c}
\toprule
\bottomrule
\label{table:mydatalabel} \\
\end{tabular}
\end{center}
似たようなことはできますか?テーブルに手動でデータを入力する必要がなくなったので、これまでのところpgfplotstablesの使用が気に入っています。
答え1
\pgfplotstabletypeset
環境内で使用する必要はありません。環境が使用されるtable
場所であればどこでも使用できます。tabular
\label
最後のコードスニペットで環境内にコマンドが出現することにこだわっているかもしれません。これも必須tabular
ではありません。\label
後、\caption
期待通りに動作します。
では、その方法を説明します。pgfplotstable
データ ファイルにアクセスできないため、マニュアルのサンプル データ ファイルを使用しました。
\documentclass{article}
\usepackage{capt-of,pgfplotstable}
\pgfplotsset{compat=1.12}
\begin{document}
Table~\ref{table:mydata} is typeset just fine by \verb|pgfplotstable|,
even outside of a \verb|table| environment.
\begin{center}
\captionof{table}[Short Caption]{This is the full, long-form caption.}
\label{table:mydata}
\pgfplotstabletypeset[columns={dof,error1}]{pgfplotstable.example1.dat}
\end{center}
\end{document}