pgfplot 中表格的放置

pgfplot 中表格的放置

如何将表格按比例缩放到 pgfplot 上?

\documentclass[]{article}
\usepackage{pgfplots, pgfplotstable}
\usepackage{booktabs}
\usepackage{caption}
\pgfplotstableread{
Current Force    FError
0     0          0
0.5   0.40e-03   0.05e-3
1     0.70e-03   0.05e-3
1.5   1.00e-03   0.05e-3
1.9   1.30e-03   0.05e-3
1.7   1.20e-03   0.05e-3
1.2   0.75e-03   0.10e-3
0.8   0.60e-03   0.05e-3
}\MyTable

\begin{document}

\begin{center}
    \captionof{table}{TabCaption}
    \label{tab:expresults}
    \pgfplotstabletypeset[
        col sep=space,
        every head row/.style={
                before row={\toprule},
                after row={\midrule}
            },
        every last row/.style={after row=\bottomrule},
        columns/Current/.style={fixed zerofill, dec sep align, sci precision=2, column name={$I$}, },
        columns/Force/.style={fixed zerofill, sci precision=1, column name={$F$}, multiply by=1000},
    ]\MyTable
\end{center}

\begin{center}
    \begin{tikzpicture}[scale=1]
            \begin{axis}[
                width=\linewidth,
                xlabel={$I$},
                ylabel=\empty,
                grid = both,
            ]

            \addplot[
                blue,
                only marks,
                error bars/.cd,
                y dir = both,  y explicit,
            ]
            table[
                    x=Current,
                    y expr={\thisrow{Force}},
                    y error = FError,
                ]\MyTable;
        \end{axis}

    \end{tikzpicture}
    \captionof{figure}{My plot}
    \label{plt:expresults}
\end{center}

\end{document}

所需结果如屏幕截图所示 在此处输入图片描述

答案1

基本上,只需将表放在 中即可\node。在添加节点之前,\end{axis}您可以使用current axis节点来放置它。此方法需要反复试验才能找到合适的text width,如果需要,可能可以避免这种情况。

\node [above left,
       text width=3.75cm, % needed to make the caption work
       fill=white,
       align=center] at (current axis.south east) {%
\vspace*{-\baselineskip}% a bit of a ugly hack, the \captionof seems to make an empty line at the start of the node
\small % reduce font size a bit
\captionof{table}{TabCaption}
    \label{tab:expresults}
    \pgfplotstabletypeset[
        col sep=space,
        every head row/.style={
                before row={\toprule},
                after row={\midrule}
            },
        every last row/.style={after row=\bottomrule},
        columns/Current/.style={fixed zerofill, dec sep align, sci precision=2, column name={$I$}, },
        columns/Force/.style={fixed zerofill, sci precision=1, column name={$F$}, multiply by=1000},
    ]\MyTable};

完整代码:

\documentclass[]{article}
\usepackage{pgfplotstable}
\usepackage{booktabs}
\usepackage{caption}
\pgfplotstableread{
Current Force    FError
0     0          0
0.5   0.40e-03   0.05e-3
1     0.70e-03   0.05e-3
1.5   1.00e-03   0.05e-3
1.9   1.30e-03   0.05e-3
1.7   1.20e-03   0.05e-3
1.2   0.75e-03   0.10e-3
0.8   0.60e-03   0.05e-3
}\MyTable

\begin{document}
\begin{center}
    \begin{tikzpicture}[scale=1]
            \begin{axis}[
                width=\linewidth,
                xlabel={$I$},
                ylabel=\empty,
                grid = both,
            ]

            \addplot[
                blue,
                only marks,
                error bars/.cd,
                y dir = both,  y explicit,
            ]
            table[
                    x=Current,
                    y expr={\thisrow{Force}},
                    y error = FError,
                ]\MyTable;

           \node [above left,
                  text width=3.75cm,
                  fill=white,
                  align=center] at (current axis.south east) {%
\vspace*{-\baselineskip}% a bit of a ugly hack, the \captionof seems to make an empty line at the start of the node
\small%
\captionof{table}{TabCaption}
    \label{tab:expresults}
    \pgfplotstabletypeset[
        col sep=space,
        every head row/.style={
                before row={\toprule},
                after row={\midrule}
            },
        every last row/.style={after row=\bottomrule},
        columns/Current/.style={fixed zerofill, dec sep align, sci precision=2, column name={$I$}, },
        columns/Force/.style={fixed zerofill, sci precision=1, column name={$F$}, multiply by=1000},
    ]\MyTable};
        \end{axis}

    \end{tikzpicture}
    \captionof{figure}{My plot}
    \label{plt:expresults}
\end{center}

\end{document}

在此处输入图片描述

相关内容