2

I have a table that I want to plot, and to print as a table using pgfplots and pgfplotstable. The table has multiple columns that could be grouped by a category. While I am happy to do the grouping manually, without cmidrules it becomes hard to tell where the border between the categories is.

Is there a more elegant solution than every row no <X>/.style={after row=\cmidrule{1-2}}? (I.e. can this be added in the table.dat)

Here a screenshot to clarify: left is what I can get, right is what I want

enter image description here

MWE:

\documentclass{article}
\RequirePackage{filecontents}
\begin{filecontents*}{table.dat}
%throughput = GHz
%frequency  = GHz
number          mode
    .137000000  {32 bit simplex}
    .539000000  \multirow{3}{*}{64 bit simplex}
   1.000000000  {}
   2.130000000  {}
   5.007000000  \multirow{3}{*}{x16 duplex}
   6.000000000  {}
   9.000000000  {}
\end{filecontents*}

\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow}

\usepackage{pgfplotstable}

\pgfplotstableset{% Global config
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule},
    assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{\textbf{#1}}}
}

\begin{document}

\pgfplotstabletypeset[
    columns={number, mode},
    columns/number/.style={%
        column type={S[round-mode=places,round-precision=3]}, string type
    }, 
    columns/mode/.style={
        string type, column type={l}
    },
    precision=0,%, fixed zerofill
    outfile = debug.dat
]{table.dat}
\end{document}

Desired table:

\begin {tabular}{S[round-mode=places,round-precision=3]l}%
\toprule \textbf {number}&\textbf {mode}\\\midrule %
.137000000&32 bit simplex\\%
\cmidrule{1-2}
.539000000&\multirow {3}{*}{64 bit simplex}\\%
1.000000000&\\%
2.130000000&\\%
\cmidrule{1-2}
5.007000000&\multirow {3}{*}{x16 duplex}\\%
6.000000000&\\%
9.000000000&\\\bottomrule %
\end {tabular}%
4

UPDATE: Sorry for the long wait, here is the thingy with the dummy column.

\documentclass{article}
\RequirePackage{filecontents}
\begin{filecontents*}{table.dat}
%throughput = GHz
%frequency  = GHz
   number          mode   dummy 
    .137000000  {32 bit simplex} \pfft
    .539000000  \multirow{3}{*}{64 bit simplex} {}
   1.000000000  {} {}
   2.130000000  {} \pfft
   5.007000000  \multirow{3}{*}{x16 duplex} {}
   6.000000000  {} {}
   9.000000000  {} {}
\end{filecontents*}

\def\pfft{\empty}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow}

\usepackage{pgfplotstable}
\pgfplotsset{compat=1.16} 

\pgfplotstableset{% Global config
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule},
    assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column
    name}{{\textbf{#1}}},
}

\begin{document}


\pgfplotstabletypeset[
typeset cell/.append code={%
\ifx#1\pfft%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\\ \midrule}%
\fi
    },%<-added
    columns={number, mode,[index]2},
    columns/number/.style={%
        column type={S[round-mode=places,round-precision=3]}, string type
    }, 
    columns/mode/.style={
        string type, column type={l}
    },
    columns/dummy/.style={string type,column name={}},
    precision=0,%, fixed zerofill
    outfile = debug.dat
]{table.dat}
\end{document}

enter image description here

EDIT: If you really want to manually insert it, you do not need any of the stuff below.

\documentclass{article}
\RequirePackage{filecontents}
\begin{filecontents*}{table.dat}
%throughput = GHz
%frequency  = GHz
number          mode
    .137000000  {32 bit simplex}
   \midrule .539000000  \multirow{3}{*}{64 bit simplex}
   1.000000000  {}
   2.130000000  {}
   \midrule 5.007000000  \multirow{3}{*}{x16 duplex}
   6.000000000  {}
   9.000000000  {}
\end{filecontents*}

\def\pfft{\empty}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow}

\usepackage{pgfplotstable}

\pgfplotstableset{% Global config
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule},
    assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{\textbf{#1}}}
}

\begin{document}

\pgfplotstabletypeset[columns={number, mode},
    columns/number/.style={%
        column type={S[round-mode=places,round-precision=3]}, string type
    }, 
    columns/mode/.style={
        string type, column type={l}
    },
    precision=0,%, fixed zerofill
    outfile = debug.dat
]{table.dat}
\end{document}

enter image description here

Just add every nth row={3[+1]}{before row=\midrule}, to the options.

\documentclass{article}
\RequirePackage{filecontents}
\begin{filecontents*}{table.dat}
%throughput = GHz
%frequency  = GHz
number          mode
    .137000000  {32 bit simplex}
    .539000000  \multirow{3}{*}{64 bit simplex}
   1.000000000  {}
   2.130000000  {}
   5.007000000  \multirow{3}{*}{x16 duplex}
   6.000000000  {}
   9.000000000  {}
\end{filecontents*}

\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow}

\usepackage{pgfplotstable}

\pgfplotstableset{% Global config
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule},
    assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{\textbf{#1}}}
}

\begin{document}

\pgfplotstabletypeset[every nth row={3[+1]}{before row=\midrule}, %<-added
    columns={number, mode},
    columns/number/.style={%
        column type={S[round-mode=places,round-precision=3]}, string type
    }, 
    columns/mode/.style={
        string type, column type={l}
    },
    precision=0,%, fixed zerofill
    outfile = debug.dat
]{table.dat}
\end{document}

enter image description here

And if you have different multirows, you may want to trigger the \midrule by something. You can replace \pfft by whatever, it is just a placeholder for a trigger that says "do something after this row".

\documentclass{article}
\RequirePackage{filecontents}
\begin{filecontents*}{table.dat}
%throughput = GHz
%frequency  = GHz
number          mode
    .137000000  {32 bit simplex}
    .539000000  \multirow{3}{*}{64 bit simplex}
   1.000000000  {}
   2.130000000  {\pfft}
   5.007000000  \multirow{3}{*}{x16 duplex}
   6.000000000  {}
   9.000000000  {}
\end{filecontents*}

\def\pfft{\empty}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{multirow}

\usepackage{pgfplotstable}

\pgfplotstableset{% Global config
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule},
    assign column name/.code=\pgfkeyssetvalue{/pgfplots/table/column name}{{\textbf{#1}}}
}

\begin{document}

\pgfplotstabletypeset[typeset cell/.append code={%
\ifx#1\pfft%
\pgfkeyssetvalue{/pgfplots/table/@cell content}{\\ \midrule}%
\fi
    },%<-added
    %every nth row={3[+1]}{before row=\midrule}, 
    columns={number, mode},
    columns/number/.style={%
        column type={S[round-mode=places,round-precision=3]}, string type
    }, 
    columns/mode/.style={
        string type, column type={l}
    },
    precision=0,%, fixed zerofill
    outfile = debug.dat
]{table.dat}
\end{document}
  • This is very close to what I am looking for. I am looking at the second case, manualy inserting \pfft. However, I would have to insert \pfftafter the first row with data ({32 bit simplex}\pfft). This does not trigger the midrule insertion, as string+macro != macro, I tried adapting your example usingIfSubStr, however I either get a Use of IfSubStr doesn't mathc its definition` error (\IfSubStr{#1}{pfft}{\pgfkeyssetvalue{/pgfplots/table/@cell content}{\\ \midrule}}{}) or an illegal parameter number error if I use {##1} instead. – ted May 3 '18 at 14:09
  • @ted OK, if you want to manually insert this, then you do not need any of these, please have a look at my update. – user121799 May 3 '18 at 16:02
  • I first thought this to be a brilliant solution, but there is a catch: to my understanding this works on the assumption that I can prepend \midrule to the first column of my table. However, I generate a graph based on the first column of the table. For obvious reasons, this throws the parser of. So unfortunately I can't simply prepend \midrule to the first column. However, the mode column is only used in the table, so adding a macro there works fine. Is it possible to adjust the \pfft macro detection solution? – ted May 4 '18 at 18:20
  • @ted I am sorry, I do not understand what precisely the problem is. What precisely do you parse? And why does your parser not struggle with the \multirows? (I mean if it can deal with those, shouldn't it be possible to let it deal with \midrules as well?) – user121799 May 4 '18 at 18:24
  • it is the pgfplots parser my actual table has several columns, to explain this lets just add a column x. I use pgfplots to plot columns x and number. Additionally I use pgfplotstable to create a table based on number,x and mode in that order. As pgfplots does not have to deal with the mode column I can insert any text. However, the number column must be parseable as a number for pgfplots. unfortunately number happens to be the first column in my table. Adding \midrule to the mode column which is not the first column does not work. – ted May 4 '18 at 18:29

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.