pgfplotstable - 删除第一列之前和最后一列之后的空格 - @{}

pgfplotstable - 删除第一列之前和最后一列之后的空格 - @{}

我正在使用pgfplotstable,我想删除第一列之前和最后一列之后的空格。
在常规表格环境中,我只需@{}在参数中使用两次即可。

\documentclass{scrartcl}

\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{pgfplots}
    \pgfplotsset{compat=1.16}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{pgfplotstable}

\begin{document}

\begin{table}[]
    \centering
    \footnotesize
    \caption{Messdaten}
    \label{tab:data}
    \pgfplotstabletypeset[
        header=true,
        col sep=semicolon,
        use comma,
        columns={h,vin50,vout50,vin100,vout100,vin150,vout150},
        columns/h/.style=      {dec sep align, fixed zerofill, precision=1,column type/.add={@{}}{}},
        columns/vin50/.style=  {dec sep align, fixed zerofill, precision=2},
        columns/vout50/.style= {dec sep align, fixed zerofill, precision=2},
        columns/vin100/.style= {dec sep align, fixed zerofill, precision=2},
        columns/vout100/.style={dec sep align, fixed zerofill, precision=2},
        columns/vin150/.style= {dec sep align, fixed zerofill, precision=2},
        columns/vout150/.style={dec sep align, fixed zerofill, precision=2,column type/.add={}{@{}}},
        % <dec sep align> doubles column
        % every first column/.style={ column type/.add={@{}}{} }, % this does not work
        % every last column/.style={ column type/.add={}{@{}} }, % this does not work
        every head row/.style={
            output empty row,
            before row={
                \toprule
                % pay attention to column doubline due to <dec sep align>
                && % empty: first two columns
                \multicolumn{4}{c}{\SI{50}{kHz}}  &
                \multicolumn{4}{c}{\SI{100}{kHz}} &
                \multicolumn{4}{c}{\SI{150}{kHz}} \\
                %
                \cmidrule(lr){3-6}
                \cmidrule(lr){7-10}
                \cmidrule(lr){11-14}
                %
                \multicolumn{2}{c}{$h$}       &
                \multicolumn{2}{c}{$V_{in}$}  &
                \multicolumn{2}{c}{$V_{out}$} &
                \multicolumn{2}{c}{$V_{in}$}  &
                \multicolumn{2}{c}{$V_{out}$} &
                \multicolumn{2}{c}{$V_{in}$}  &
                \multicolumn{2}{c}{$V_{out}$} \\
                %
                \cmidrule(r){1-2}
                \cmidrule(lr){3-4}
                \cmidrule(lr){5-6}
                \cmidrule(lr){7-8}
                \cmidrule(lr){9-10}
                \cmidrule(lr){11-12}
                \cmidrule(l){13-14}
                %
                \multicolumn{2}{c}{\si{cm}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} \\
            },
            after row=\midrule,
        },
        every last row/.style={after row=\bottomrule},
    ]{lab01-data.csv}
\end{table}

\end{document}

我的.csv文件(lab01-data.csv):

h;vin50;vout50;vin100;vout100;vin150;vout150
25;99.68;57.29;98.87;43.83;98.51;33.85
22.5;99.81;60.45;99.01;46.05;98.29;36.39
20;99.71;63.45;99.05;50.51;98.45;40.1
17.5;99.89;67;99.1;54.45;98.37;43.3
15;99.85;71.3;99.2;59.65;98.6;49.01
12.5;100.04;75.69;99.39;65.31;98.58;54.06
10;100.12;80.49;99.6;71.86;98.92;62.45
7.5;100.31;85.25;99.75;78.75;99.05;70.59
5;100.38;90.3;100.06;86.28;99.51;80.61
2.5;100.59;95.29;100.25;93.18;99.81;90.49
0;100.62;99.75;100.51;99.94;100.22;98.9

PGF绘图表

第一列和最后一列的数据部分看起来正确,但标题错误。第一列中的hcm,以及最后一列中的V_{out}mV未正确对齐。

我确实尝试添加column type/.add={@{}}{}和,column type/.add={}{@{}}但这不适用于多列单元格。指定多列单元格的对齐方式(rl)没有帮助。

这两行根本没有任何效果。

every first column/.style={ column type/.add={@{}}{} }, % this does not work
every last column/.style={ column type/.add={}{@{}} }, % this does not work

答案1

问题不是pgfplotstable,您必须将@{}也放在每个第一个(@{}c)和每个最后一个( )多列规范中(并在第一个标题行之后c@{}调整最后一个)。\cmidrule

我从一位大师那里学到:标题中的 \makecell:如何去除表格最后一列后的空格?

\documentclass{scrartcl} 
\usepackage{filecontents}
\begin{filecontents*}{lab01-data.csv}
    h;vin50;vout50;vin100;vout100;vin150;vout150 
    25;99.68;57.29;98.87;43.83;98.51;33.85 
    22.5;99.81;60.45;99.01;46.05;98.29;36.39 
    20;99.71;63.45;99.05;50.51;98.45;40.1 
    17.5;99.89;67;99.1;54.45;98.37;43.3 
    15;99.85;71.3;99.2;59.65;98.6;49.01 
    12.5;100.04;75.69;99.39;65.31;98.58;54.06 
    10;100.12;80.49;99.6;71.86;98.92;62.45 
    7.5;100.31;85.25;99.75;78.75;99.05;70.59 
    5;100.38;90.3;100.06;86.28;99.51;80.61 
    2.5;100.59;95.29;100.25;93.18;99.81;90.49 
    0;100.62;99.75;100.51;99.94;100.22;98.9
\end{filecontents*}

\usepackage{amsmath}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{array}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{pgfplotstable}

\begin{document}

    \begin{table}[]
        \centering
        \footnotesize
        \caption{Messdaten}
        \label{tab:data}
        \pgfplotstabletypeset[
        header=true,
        col sep=semicolon,
        use comma,
        columns={h,vin50,vout50,vin100,vout100,vin150,vout150},
        columns/h/.style=      {dec sep align, fixed zerofill, precision=1,column type/.add={@{}}{}},
        columns/vin50/.style=  {dec sep align, fixed zerofill, precision=2},
        columns/vout50/.style= {dec sep align, fixed zerofill, precision=2},
        columns/vin100/.style= {dec sep align, fixed zerofill, precision=2},
        columns/vout100/.style={dec sep align, fixed zerofill, precision=2},
        columns/vin150/.style= {dec sep align, fixed zerofill, precision=2},
        columns/vout150/.style={dec sep align, fixed zerofill, precision=2,column type/.add={}{@{}}},
        % <dec sep align> doubles column
        % every first column/.style={ column type/.add={@{}}{} }, % this does not work
        % every last column/.style={ column type/.add={}{@{}} }, % this does not work
        every head row/.style={
            output empty row,
            before row={
                \toprule
                % pay attention to column doubline due to <dec sep align>
                && % empty: first two columns
                \multicolumn{4}{c}{\SI{50}{kHz}}  &
                \multicolumn{4}{c}{\SI{100}{kHz}} &
                \multicolumn{4}{c@{}}{\SI{150}{kHz}} \\
                %
                \cmidrule(lr){3-6}
                \cmidrule(lr){7-10}
                \cmidrule(l){11-14}
                %
                \multicolumn{2}{@{}c}{$h$}       &
                \multicolumn{2}{c}{$V_{in}$}  &
                \multicolumn{2}{c}{$V_{out}$} &
                \multicolumn{2}{c}{$V_{in}$}  &
                \multicolumn{2}{c}{$V_{out}$} &
                \multicolumn{2}{c}{$V_{in}$}  &
                \multicolumn{2}{c@{}}{$V_{out}$} \\
                %
                \cmidrule(r){1-2}
                \cmidrule(lr){3-4}
                \cmidrule(lr){5-6}
                \cmidrule(lr){7-8}
                \cmidrule(lr){9-10}
                \cmidrule(lr){11-12}
                \cmidrule(l){13-14}
                %
                \multicolumn{2}{@{}c}{\si{cm}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c}{\si{mV}} &
                \multicolumn{2}{c@{}}{\si{mV}} \\
            },
            after row=\midrule,
        },
        every last row/.style={after row=\bottomrule},
        ]{lab01-data.csv}
    \end{table}

\end{document}

在此处输入图片描述

相关内容