6

I am using pgfplotstable and I want to remove the space before the first column and after the last column.
In a regular tabular environment I would just use @{} twice in the argument.

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

My .csv file (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

PGFPlotsTable

The part of the first and last columns with the data looks right but the header is wrong. In the first column h and cm, and on the last column V_{out} and mV are not properly aligned.

I did try to add column type/.add={@{}}{} and column type/.add={}{@{}} but this won't work with the multicolumn cell. Specifying the alignment of the multicolumn cells (r and l) didn't help.

Those two lines have no effect at all.

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

The problem is not pgfplotstable, you have to put the @{} also in every first (@{}c) and every last (c@{}) multicolumn specs (and adjust the last \cmidrule after the first heading row).

I learnt from a master: \makecell in the header: how to get rid of the space after the last column of the table?

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

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.