1

Due to a recommendation on this board, I have decided to use pgfplotstable in my lab reports to import data from a CSV and print it out as a table in LaTeX. However, in a section such as my appendices, I need tables to be under headings (not above them), so how can I force LaTeX to place the table where I put it in my code.

Sample:

\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 will do its automatic formatting and place my tables above Heading 1 (and other headings too).

Before the use of pgfplotstables, I used this code for my tables to force them where they are meant to be:

\begin{center}
    \captionof{table}[LoT Caption]{Full Caption}        
    \begin{tabular}{c c c c}
        \toprule

        \bottomrule
        \label{table:mydatalabel} \\
    \end{tabular}
\end{center}

Is there something similar I can do? I really like using pgfplotstables so far since I don't have to manually enter data into tables anymore

  • 1
    Did you try it? I don't have your data file, so I can't test, but as far as I know, nothing is preventing you from replacing \begin{tabular}...\end{tabular} with \pgfplotstabletypeset[...]{...} in your last code snippet. The \label{} does not need to be inside the tabular environment: as long as it comes after \caption it's fine. – Paul Gessler Feb 18 '15 at 22:35
  • 2
    It is nothing to do with pgfplots table, just the behavoiour of the table environment see http://tex.stackexchange.com/questions/2275/keeping-tables-figures-close-to-where-they-are-mentioned – David Carlisle Feb 18 '15 at 22:39

1 Answers1

1

Nothing requires \pgfplotstabletypeset to be used inside of a table environment; it can be used anywhere a tabular environment might be used.

You may be hung up on the \label command appearing inside the tabular environment in your last code snippet. There's no requirement for this, either. As long as the \label comes after the \caption, it will work as expected.

So here is how it could be done. I used the example data file from the pgfplotstable manual since I do not have access to your data file:

\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}

enter image description here

Paul Gessler
  • 29,607