You can use \multicolumn
to override the column specification given in the table format:
\documentclass{article}
\begin{document}
\begin{table}[htdp]
\centering
\caption{A table}
\begin{tabular}{c|c|c|c|c|}
\multicolumn{1}{c}{} & \multicolumn{1}{c}{00} & \multicolumn{1}{c}{01} & \multicolumn{1}{c}{11} & \multicolumn{1}{c}{10} \\ \hline
0&1&1&1&1\\
1&0&0&0&0\\
\end{tabular}
\label{default}
\end{table}
\end{document}
I used \centering
instead of the center
environment to prevent extra vertical spacing. Are you sure you need vertical rules at all?
The booktabs package can help you improve your tables; the package documentation gives useful advice on formatting tables. Even in this little example the results are better; compare the vertical spacing of the horizontal rule using booktabs
:
\documentclass{article}
\usepackage{booktabs}
\begin{document}
\begin{table}[htdp]
\centering
\caption{A table}
\begin{tabular}{ccccc}
& 00 & 01 & 11 & 10 \\
\midrule
0 & 1 & 1 & 1 & 1 \\
1 & 0 & 0 & 0 & 0 \\
\end{tabular}
\label{default}
\end{table}
\end{document}
As SlowLearner suggested, you can get rid of the quotation marks in the data table by setting quote=F
in your R script. However, this leaves the column name for the first column empty, which PGFPlotstable can't handle.
I've modified the PGFPlotstable function that assigns the column names to check whether the column name would be empty, and replaces empty column names with the string empty
, so you can work with it like with a "normal" column (for example, setting /columns/empty/.style={column name={}}
to prevent \pgfplotstabletypeset
from printing the empty
string).
\documentclass{article}
\usepackage{pgfplotstable,filecontents,booktabs}
%% Redefine an internal PGFPlotstable macro to check for empty column names
\makeatletter
\long\def\pgfplotstableread@impl@collectcolnames@NEXT#1{%
%\pgfplots@message{Got column name no \thepgfplotstableread@curcol\ as '#1'}%
\pgfutil@ifundefined{pgfplotstableread@impl@COLNAME@#1}{%
\if\relax\detokenize{#1}\relax
\def\pgfplotstable@loc@TMPa{empty}%
\else
\def\pgfplotstable@loc@TMPa{#1}%
\fi
}{% generate unique column names warning:
\if\relax\detokenize{#1}\relax
\def\pgfplotstable@loc@TMPa{empty}%
\else
\def\pgfplotstable@loc@TMPa{#1}%
\fi
\pgfplots@warning{Table '\pgfplotstableread@filename' has non-unique column name '\pgfplotstable@loc@TMPa'. Only the first occurence can be accessed via column names.}%
\edef\pgfplotstable@loc@TMPa{\pgfplotstable@loc@TMPa--index\thepgfplotstableread@curcol}%
}%
\expandafter\def\csname pgfplotstableread@impl@COLNAME@#1\endcsname{foo}% remember this name.
\expandafter\pgfplotslistpushbackglobal\expandafter{\pgfplotstable@loc@TMPa}\to\pgfplotstable@colnames@glob
\ifpgfplots@tableread@to@listener
% create an associative container colindex -> colname
% for use in a listener.
\expandafter\edef\csname pgfplotstblread@colindex@for@name#1\endcsname{\thepgfplotstableread@curcol}%
\fi
\pgfplotstableread@countadvance\pgfplotstableread@curcol
}
\makeatother
\pgfplotstableread[col sep=comma]{test.csv}\tablea
%Start the document
\begin{document}
% Table a
\pgfplotstabletypeset[
columns/empty/.style={column name={}, string type},
columns/pe/.style={column name=PE, fixed, fixed zerofill, precision=3, dec sep align},
columns/se/.style={column name=SE, fixed, fixed zerofill, precision=3,dec sep align},
every head row/.style={before row={\toprule},after row=\midrule},
every last row/.style={after row={\toprule}},
]\tablea
\end{document}
Best Answer
Tha table could be improved using
hhline
: it helps double lines intersect nicely with other (single or double) lines. I also used themakecell
package that is designed to allow linebreaks inside tabular cells (and also common formatting of cells contents):