2

The file I want to show is a .tsv file that I cannot edit. It looks like this:

up_gene up_chr  up_strand   up_Genome_pos
APLP2   chr11   +   129991686
BACE2   chr21   +   42617990
BRDT    chr1    +   92470856
CTBS    chr1    -   85028940
DHRS1   chr14   -   24761405

But when reading this I get a Missing $ inserted error. Minimal example:

\documentclass{article}
\usepackage{pgfplotstable}
% recommended:
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}

\begin{document}

\pgfplotstabletypeset[
  every even row/.style={
    before row={
      \rowcolor[gray]{0.9}
    }
  },
  every head row/.style={
    before row=\toprule,
    after row=\midrule
  },
  every last row/.style={
    after row=\bottomrule
  },
  string type,
  columns={up_gene,up_chr},
]
{results.tsv}

\end{document}

Which results in the error mentioned above, and this output:

enter image description here

So I have two questions:

  1. How can I avoid the error I get? Note that the same error arise even if I remove columns={up_gene,up_chr}
  2. How can I get the underscore in the header to show? I don't want to subscript the g in up_gene.
2
  • have you tried tex.stackexchange.com/questions/51192/…
    – percusse
    Apr 25, 2016 at 11:43
  • Thank you for answering. Yes, I did try to do something with columns/A_d/.style, with A_d exchanged for my header name, but I was not able to get it working.
    – L42
    Apr 25, 2016 at 12:47

1 Answer 1

2

You can set the column names yourself:

\documentclass{article}
\usepackage{pgfplotstable}
% recommended:
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}

\begin{document}

\pgfplotstabletypeset[
  string type,
  columns={up_gene,up_chr},
  columns/up_gene/.style={column name=up\_gene},
  columns/up_chr/.style={column name=up\_chr},
  every even row/.style={
    before row={
      \rowcolor[gray]{0.9}
    }
  },
  every head row/.style={
    before row=\toprule,
    after row=\midrule
  },
  every last row/.style={
    after row=\bottomrule
  },
]{results.tsv}

\end{document}

enter image description here

It is possible to cope with underscores in a different way, but it requires changing the category code of _, which might have adverse effects if math formulas are involved; also loading fontenc with the T1 option is necessary.

Here the two typesettings are shown side by syde: right as above, left with the columns selected by their indices and the change in the category code.

\documentclass{article}
\usepackage[T1]{fontenc}

\usepackage{pgfplotstable}
% recommended:
\usepackage{booktabs}
\usepackage{array}
\usepackage{colortbl}

\begin{document}

\pgfplotstabletypeset[
  string type,
  columns={up_gene,up_chr},
  columns/up_gene/.style={column name=up\_gene},
  columns/up_chr/.style={column name=up\_chr},
  every even row/.style={
    before row={
      \rowcolor[gray]{0.9}
    }
  },
  every head row/.style={
    before row=\toprule,
    after row=\midrule
  },
  every last row/.style={
    after row=\bottomrule
  },
]{results.tsv}
%
\begingroup\catcode`_=12
\pgfplotstabletypeset[
  string type,
  columns={[index]0,[index]1},
  every even row/.style={
    before row={
      \rowcolor[gray]{0.9}
    }
  },
  every head row/.style={
    before row=\toprule,
    after row=\midrule
  },
  every last row/.style={
    after row=\bottomrule
  },
]{results.tsv}
\endgroup

\end{document}

enter image description here

4
  • Thank you! Do you have a clue what I could do if I didn't know beforehand what the column names were?
    – L42
    Apr 25, 2016 at 15:43
  • @L42 That I don't know. In my opinion there should be a function for “postprocessing” the found column name, say for applying \textbf or similar; in this case one could apply \detokenize or do a more sophisticated approach with string substitutions.
    – egreg
    Apr 25, 2016 at 15:46
  • Is there any way to do this automatically. Eg if I don't know exactly know the column names but I just want to replace _ by \_ in each column name?
    – Peutch
    Sep 22, 2017 at 15:42
  • 1
    @Peutch Your hope is fulfilled.
    – egreg
    Sep 22, 2017 at 20:03

You must log in to answer this question.

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