5

trying to create a table using pgfplotstable, but I'm having errors when I want to write Greek letters (actually, any math mode symbol starting with '\'). Where I have 'a' and 'b' I would like to have an alpha and a beta. Can you help me?

Here's my code:

\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs,colortbl,pgfplotstable}
\definecolor{rulecolor}{RGB}{0,71,171}
\definecolor{tableheadcolor}{gray}{0.92}

\newcommand{\topline}{ %
    \arrayrulecolor{rulecolor}\specialrule{0.1em}{\abovetopsep}{0pt}%
    \arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
    \arrayrulecolor{rulecolor}}

\newcommand{\midtopline}{ %
    \arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
    \arrayrulecolor{rulecolor}\specialrule{\lightrulewidth}{0pt}{0pt}%
    \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
    \arrayrulecolor{rulecolor}}

\newcommand{\bottomline}{ %
    \arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
    \arrayrulecolor{rulecolor} %
    \specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%

\newcommand{\midheader}[2]{%
    \midrule\topmidheader{#1}{#2}}

\newcommand\topmidheader[2]{\multicolumn{#1}{c}{\textsc{#2}}\\%
            \addlinespace[0.5ex]}

\pgfplotstableset{mystyle/.style ={%
    header=true,
    string type,
    column type=c,
    every odd row/.style={
        before row=
    },       
    every first column/.style={
        column type=l
    },        
    every head row/.style={
        before row={\topline\rowcolor{tableheadcolor}},
        after row={\midtopline},
    },
    every last row/.style={
        after row=\bottomline
    },
    col sep=&,
    row sep=\\
 }
}

\begin{document}
 \begin{table}
    \centering
    \pgfplotstabletypeset[mystyle]{
    {$ $}        & {$a$}                 &  {$b$} \\
    {0}        & {10}                &  {$1000$}\\     
    }
 \end{table}
\end{document}
  • Welcome to TeX.SE! Probably this answer is related. (I am not saying your question is a duplicate.) – user121799 Mar 8 '18 at 18:42
  • or see example on the top of page 17, documentation for pgfplotstable. – Zarko Mar 8 '18 at 19:06
4

As Zarko noted, the example shown on pages 17-18 of the manual for pgfplotstablemakes use of one of the possible solutions to your problem.

The format used is explained at the end of page 11 in the same manual:

columns/{lowlevel colname}/.style={column name = display column name}
Here, lowlevel colname refers to the column name that is present in your input table. This lowlevel column name has a couple of restrictions (it has to be expandable, for example - that means many control sequences are forbidden). The value of column name is only used within \pgfplotstabletypeset in order to generate a display name for the column in question.

I have included the solution to your question below, and the result obtained after compilation. You will find my modifications in the [< options >] of \pgfplotstabletypeset.

\documentclass{article}
\usepackage{xcolor}
\usepackage{booktabs,colortbl,pgfplotstable}
\definecolor{rulecolor}{RGB}{0,71,171}
\definecolor{tableheadcolor}{gray}{0.92}

\newcommand{\topline}{ %
    \arrayrulecolor{rulecolor}\specialrule{0.1em}{\abovetopsep}{0pt}%
    \arrayrulecolor{tableheadcolor}\specialrule{\belowrulesep}{0pt}{0pt}%
    \arrayrulecolor{rulecolor}}

\newcommand{\midtopline}{ %
    \arrayrulecolor{tableheadcolor}\specialrule{\aboverulesep}{0pt}{0pt}%
    \arrayrulecolor{rulecolor}\specialrule{\lightrulewidth}{0pt}{0pt}%
    \arrayrulecolor{white}\specialrule{\belowrulesep}{0pt}{0pt}%
    \arrayrulecolor{rulecolor}}

\newcommand{\bottomline}{ %
    \arrayrulecolor{white}\specialrule{\aboverulesep}{0pt}{0pt}%
    \arrayrulecolor{rulecolor} %
    \specialrule{\heavyrulewidth}{0pt}{\belowbottomsep}}%

\newcommand{\midheader}[2]{%
    \midrule\topmidheader{#1}{#2}}

\newcommand\topmidheader[2]{\multicolumn{#1}{c}{\textsc{#2}}\\%
            \addlinespace[0.5ex]}

\pgfplotstableset{mystyle/.style ={%
    header=true,
    string type,
    column type=c,
    every odd row/.style={
        before row=
    },       
    every first column/.style={
        column type=l
    },        
    every head row/.style={
        before row={\topline\rowcolor{tableheadcolor}},
        after row={\midtopline},
    },
    every last row/.style={
        after row=\bottomline
    },
    col sep=&,
    row sep=\\
 }
}

\begin{document}
 \begin{table}
    \centering
    \pgfplotstabletypeset[mystyle, 
    columns/a/.style={column name=$\alpha$},
    columns/b/.style={column name=$\beta$},
]{
    {$ $}        & {a}                 &  {b} \\
    {0}        & {10}                &  {$1000$}\\     
    }
 \end{table}
\end{document}

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.