\pgfplotstabletranspose 中的列宽以逗号作为小数点分隔符

\pgfplotstabletranspose 中的列宽以逗号作为小数点分隔符

我正在尝试绘制一个名为 .dat 文件的数据,Analysis.dat该文件如下所示:

number   $Test1$   $Test2$   $Test3$
1   121.14   117.92   122.67
2   121.29   117.40   121.16
3   121.66   116.49   120.90
4   119.59   112.66   118.60
5   116.10   109.19   114.48
6   110.34   108.63   106.26

LaTeX 中的当前图如下所示: 这是当前的情节

我在图表下方尝试概念化一个数据表。现在我想将表格列完美地对齐在图表下方,这样表格中的“数字”(1、2、3、4、5、6)就位于图表数字的正下方(例如,上面的屏幕截图中的数字 1 几乎完美对齐)。

当使用点作为小数点分隔符时,我可以使用“ column type={p{1cm}} ”来修改列宽,例如但是现在,使用逗号作为小数点分隔符时,这不再起作用,并且我收到错误:

! Extra alignment tab has been changed to \cr. 

有人知道如何解决这个错误吗?我会很感激大家的帮助!这将是上面截图的代码:

\documentclass[varwidth=\maxdimen, border={59pt, 0pt, 0pt, 0pt}]{standalone}
\usepackage{standalone}
\usepackage{tikz, xcolor}
\usepackage[ngerman]{babel}
\usepackage{pgfplots}
\usepackage{array}
\usepackage{pgfplotstable}
\pgfplotsset{compat=newest}
\usepackage{booktabs,colortbl}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
    x = 2.75cm,
    ticklabel style ={/pgf/number format/.cd, use comma, 1000 sep = {}},
    xlabel=\large number ,
    ylabel=\large seconds ,
    title=\Large mean cycle time,
    xmin= 1,
    xmax= 6,
    xtick={1,2,...,6},
    ytick={106, 108, 110,...,124},
    legend pos=north east,
    ymajorgrids=true,
    grid style=dashed,
    grid = both,
    axis background/.style={fill=white!10}],
]
\addplot table [x={number}, y={$Test1$}]{Analysis.dat};
\addplot table[x={number}, y={$Test2$}]{Analysis.dat};
\addplot[mark = diamond*] table[x={number}, y={$Test3$}] {Analysis.dat};
\legend{$Test1$\\$Test2$\\$Test3$\\}
\end{axis}
\end{tikzpicture}
\\
\noindent
\pgfplotstabletranspose[colnames from=number, input colnames to=number]\loadedtable{Analysis.dat}
\vspace{-3.5cm}
\hspace{-1.5cm}
\pgfplotstabletypeset[use comma, string type,every even row/.style={
before row={}},  
every head row/.style={
before row=\toprule,after row=\midrule},
every last row/.style={
after row=\bottomrule},
every column/.style={ column type={p{1.65cm}}},
columns/1/.style={dec sep align, zerofill},
columns/2/.style={dec sep align, zerofill},
columns/3/.style={dec sep align,zerofill},
columns/4/.style={dec sep align,zerofill},
columns/5/.style={dec sep align,zerofill},
columns/6/.style={dec sep align,zerofill}]\loadedtable
\end{document}

答案1

你是指以下情况吗?为此我没有修改表格,但是拉伸已移动情节。(我不想“拉伸”表格,因为这样会留下很多空白,我觉得这样看起来不太好看。)

更多详细信息请查看代码中的注释。

% used PGFPlots v1.14
    \begin{filecontents}{Analysis.dat}
        number   $Test1$   $Test2$   $Test3$
        1   121.14   117.92   122.67
        2   121.29   117.40   121.16
        3   121.66   116.49   120.90
        4   119.59   112.66   118.60
        5   116.10   109.19   114.48
        6   110.34   108.63   106.26
    \end{filecontents}
\documentclass[border=5pt]{standalone}
\usepackage{booktabs}
\usepackage{pgfplots}
\usepackage{pgfplotstable}
    \pgfplotsset{compat=1.3}
\begin{document}
    \begin{tikzpicture}
        % first plot the table in a node
        \node (table) {%
            \pgfplotstabletranspose[
                colnames from=number,
                input colnames to=number,
            ]\loadedtable{Analysis.dat}%
            \pgfplotstabletypeset[
                use comma,
                string type,
                every even row/.style={
                    before row={},
                },
                every head row/.style={
                    before row=\toprule,
                    after row=\midrule,
                },
                every last row/.style={
                    after row=\bottomrule,
                },
                every column/.style={
                    column type={p{1.65cm}},
                },
                columns/1/.style={dec sep align,zerofill},
                columns/2/.style={dec sep align,zerofill},
                columns/3/.style={dec sep align,zerofill},
                columns/4/.style={dec sep align,zerofill},
                columns/5/.style={dec sep align,zerofill},
                columns/6/.style={dec sep align,zerofill},
            ]{\loadedtable}
        };
        % then create a dummy coordinate above the table where the diagram
        % will be plotted
        % (for the vertical shift adapt the `yshift' and for aligning the
        %  "x" numbers of the table and plot adapt the `xshift')
        \coordinate (above table) at
            ([yshift=2ex,xshift=2.6ex] table.north);

        \begin{axis}[
            % position the plot at the previously created dummy coordinate
            % and set the anchor accordingly
            at={(above table)},
            anchor=outer south,
            % adjust `x' (or alternatively `width') to find the right
            % "stretching" of the plot
            x=14mm,
            ticklabel style ={
                /pgf/number format/.cd,
                    use comma,
                    1000 sep={},
            },
            xlabel=\large number ,
            ylabel=\large seconds ,
            title=\Large mean cycle time,
            legend pos=north east,
            ymajorgrids=true,
            grid style=dashed,
            grid=both,
        ]
            \addplot                 table [x={number},y={$Test1$}] {Analysis.dat};
            \addplot                 table [x={number},y={$Test2$}] {Analysis.dat};
            \addplot [mark=diamond*] table [x={number},y={$Test3$}] {Analysis.dat};

            \legend{$Test1$,$Test2$,$Test3$}

%            % -----------------------------------------------------------------
%            % for debugging purposes
%            \pgfplotsinvokeforeach {1,...,6} {
%                \coordinate (x#1) at (axis cs:#1,\pgfkeysvalueof{/pgfplots/ymin});
%            }
%            % -----------------------------------------------------------------

        \end{axis}

%        % ---------------------------------------------------------------------
%        % for debugging purposes
%        \foreach \i in {1,...,6} {
%            \draw [help lines] (x\i) |- (table.south);
%        }
%        % ---------------------------------------------------------------------

    \end{tikzpicture}
\end{document}

该图显示了上述代码的结果

相关内容