I'd like table to have centrally aligned columns and a vertical line between columns 2 and 3. This was possible before I included the 'dec sep align' code but afterwards the columns shifted to the left and the vertical line disappeared. Any help would be great. Here is my attempt at inputting these commands.
\documentclass[a4paper,12pt]{report}
\usepackage{tabularx}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\usepackage{multirow}
\usepackage{amssymb}
\usepackage{pgfplots,pgfplotstable,filecontents}
\usepackage{array}
\begin{document}
\begin{table}[H]
\centering
\pgfkeys{/pgf/number format/.cd,fixed, fixed zerofill}
\pgfplotstabletypeset[col sep=comma,every head row/.style={before row=\toprule,after row=\midrule},every row no 2/.style={after row=\midrule},every last row/.style={after row=\bottomrule},
columns/NG/.style={string type,column name=$M_n~(g\,m^{-2})$,column type=c,dec sep align,precision=0},
columns/ID/.style={column name=$\rho_i\,(g\,cm^{-3})$,dec sep align},
columns/R2/.style={column type=|C,column name=$r^2$,dec sep align},
columns/IN/.style={column type=C,column name=$Intercept\,(cN/tex)$,dec sep align},
columns/GR/.style={column type=C,column name=$Gradient\,\times10^{-4}$,dec sep align
},
]
{% data from file
NG,ID,R2, IN, GR
0, 0.60, 0.79, -9.30, -5.81
, 0.67, 0.87, -7.10, -4.76
, 0.71, 0.94, -6.60, -4.57
12, 0.60, 0.38, 6.01, 0.02
, 0.67, 0.08, 6.41, 0.01
, 0.71, 0.42, 6.65, -0.02
}
\end{table}
\end{document}
Also, I am unsure how to insert code into a Tex post without having to space bar 4 times for every line.
Best Answer
Using Jake's answer to another question, (column separator in header line in column with dec sep align), I have been able to add a vertical rule for you.
I'm afraid I don't know how to center the columns when
dec sep align
is active.I have taken the liberty of neatening up the formatting of your table for you, in two ways:
Units should be typeset in normal "roman" font, rather than italics. So I wrapped them in
\mathrm{...}
.You shouldn't write whole words in math mode like
$this$
, because the kerning between the letters looks wrong. (It's as if you're multiplyingt
,h
,i
ands
together.) You should write$\mathit{this}$
instead.Code