2

I have this csv file:

,Accuracy
1,0.982
2,0.982
3,0.982
4,0.988
5,0.916
6,0.976
7,0.958
8,0.97
9,0.945
10,0.988
11,0.969

This is the screenshot when I imported it into Latex file:

enter image description here

This is the working example file:

\documentclass[a4,12pt]{report}

\usepackage{pgfplotstable}

\begin{document}


    \begin{table}[h!]
        \caption{Accuracy value}
        \label{tab:cvinitial}
        \begin{center}
            \pgfplotstabletypeset[
            col sep=comma,
            header = has colnames,
            string type,
            display columns/ /.style={column type={|l|},}
            display columns/Accuracy/.style={column type={|l|}},
            every head row/.style={before row=\hline,after row=\hline},
            every nth row={1}{before row=\hline},
            every last row/.style={after row=\hline},
            ]{
            ,Accuracy
            1,0.982
            2,0.982
            3,0.982
            4,0.988
            5,0.916
            6,0.976
            7,0.958
            8,0.97
            9,0.945
            10,0.988
            11,0.969
        }
        \end{center}
    \end{table}

\end{document}

I have several questions:

  1. How can I change the first column name from 0 to another value/text, for example No?
  2. How can I change the last element of the first column name (11) to another value/text, for example Average?
  3. How do I add vertical line between columns?

Thank you in advance for the help.

1 Answer 1

1
  1. To change the predefined value of this empty cell 0 to No, I added played with assign column name. (I am not claiming it is necessarily the most elegant way.)

  2. To add a vertical bar, I played with every even column and every odd column.

  3. To replace the element of the table, I added every row 10 column 0/.style={postproc cell content/.style={@cell content=Average}},

\documentclass[a4,12pt]{report}

\usepackage{pgfplotstable}
%\pgfplotsset{compat=1.15}
\begin{document}


    \begin{table}[h!]
        \caption{Accuracy value}
        \label{tab:cvinitial}
        \begin{center}
            \pgfplotstabletypeset[
            col sep=comma,
            header=has colnames,
            assign column name/.style={
            /pgfplots/table/column name={\ifx#10
            No
            \else
            #1
            \fi}
            },
            string type,
            %display columns/ /.style={column type={|l|},}
            every odd column/.style={
                column type/.add={}{|}
            },
            every even column/.style={
                column type/.add={|}{|}
            },
            every row 10 column 0/.style={postproc cell content/.style={@cell
            content=Average}},
            every head row/.style={before row=\hline,after row=\hline},
            every nth row={1}{before row=\hline},
            every last row/.style={after row=\hline},
            ]{
            ,Accuracy
            1,0.982
            2,0.982
            3,0.982
            4,0.988
            5,0.916
            6,0.976
            7,0.958
            8,0.97
            9,0.945
            10,0.988
            11,0.969
        }
        \end{center}
    \end{table}

\end{document}

enter image description here

7
  • I got this error Package pgfplots Error: Sorry, 'compat=1.16' is unknown in this context. Please use at most 'compat=1.15'. \pgfplotsset{compat=1.16} @marmot Commented Jan 28, 2019 at 22:46
  • @AkhmadZaki This just means you do not run the most recent version of pgfplotstable. The above code works fine with \pgfplotsset{compat=1.15} or without \pgfplotsset{compat=...}.
    – user121799
    Commented Jan 28, 2019 at 22:55
  • yes, it works, but how about changing the value 11 in the first column and adding vertical line between columns @marmot ? Commented Jan 28, 2019 at 22:57
  • @AkhmadZaki I added these things.
    – user121799
    Commented Jan 28, 2019 at 23:14
  • The vertical line at the left and the right side of the table still not showing. How to add it ? Commented Jan 29, 2019 at 2:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .