Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to create a table using the pgfplotstable package. I've managed to get 95% of the formatting I want using the following:

\usepackage{pgfplotstable}
\usepackage{booktabs}

% global settings
\pgfplotstableset{
after row={\hline},
every head row/.style={
before row={
\rowcolor{lightgray}
\noalign{\hrule height \tableborder}
},
after row={
\hline
},
},
every last row/.style={
after row=\noalign{\hrule height \tableborder}
},
col sep = &,
row sep=\\,
% column type/.add={}{\vrule width \tableborder},
every col no 1/.style={ column type/.add={|}{} },
every col no 2/.style={ column type/.add={|}{} },
every col no 3/.style={ column type/.add={|}{} },
every col no 4/.style={ column type/.add={|}{} },
every col no 5/.style={ column type/.add={|}{} },
every first column/.style={
column type/.add={!{\vrule width \tableborder}}{}
},
every last column/.style={
column type/.add={}{!{\vrule width \tableborder}}
},
string type,
}

Even though there are many every col no, which I don't like, it still works almost perfectly. The only thing I'm missing is to put the header's text in bold. If I try to force it to bold in the actual table it doesn't compile, and I'm not able to change the content of the row to bold. So with this code I ask 2 questions:

1 - Hown can I get the header's text to be bold?

2 - Does anyone know of a better way to do what the every col no commands do, but in a more general way?

EDIT: Here is the complete code now (It was missing a def). And bellow the initial config is the code to generate the table.

\usepackage{pgfplotstable}
\usepackage{booktabs}
\def\tableborder{1.5pt}

% global settings
\pgfplotstableset{
after row={\hline},
every head row/.style={
before row={
\rowcolor{lightgray}
\noalign{\hrule height \tableborder}
},
after row={
\hline
},
},
every last row/.style={
after row=\noalign{\hrule height \tableborder}
},
col sep = &,
row sep=\\,
% column type/.add={}{\vrule width \tableborder},
every col no 1/.style={ column type/.add={|}{} },
every col no 2/.style={ column type/.add={|}{} },
every col no 3/.style={ column type/.add={|}{} },
every col no 4/.style={ column type/.add={|}{} },
every col no 5/.style={ column type/.add={|}{} },
every first column/.style={
column type/.add={!{\vrule width \tableborder}}{}
},
every last column/.style={
column type/.add={}{!{\vrule width \tableborder}}
},
string type,
}

With this the table is generated. Note that this is only a portion of the actual document and the table is a fake.

\pgfplotstabletypeset{
person & singEnglish & singGaeilge & pluralEnglish & pluralGaeilge\\
1st & at me & agam & at us & againn\\
2st & at you & agat & at you & agaibh\\
3st & at him & aige & at them & acu\\
& at her & aici & &\\
}

Here is the result. I want the text in the header to be bold, and the column lines to go all the way on all columns enter image description here

EDIT Nº2:

Ok now here is a sample of a compilable code (stand alone), but now it is refusing to paint the header row. Please help.

\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[english]{babel}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}

\usepackage{pgfplotstable}
\usepackage{booktabs}
\def\tableborder{1.5pt}

% global settings
\pgfplotstableset{
    after row={\hline},
    every head row/.style={
        before row={
        \noalign{\hrule height 1.5pt}
        },
        after row={
            \hline
        },  
    },
    every last row/.style={
        after row=\noalign{\hrule height 1.5pt}
    },
    col sep = &,
    row sep=\\,
    % column type/.add={}{\vrule width \tableborder},
    every col no 1/.style={ column type/.add={|}{} },
    every col no 2/.style={ column type/.add={|}{} },
    every col no 3/.style={ column type/.add={|}{} },
    every col no 4/.style={ column type/.add={|}{} },
    every col no 5/.style={ column type/.add={|}{} },
    every first column/.style={
        column type/.add={!{\vrule width 1.5pt}}{}
    },
    every last column/.style={
        column type/.add={}{!{\vrule width 1.5pt}}
    },
    string type,
}

\begin{document}
\pgfplotstabletypeset{
1 & 2 & 4 \\
3 & 4 & 9 \\
}
\end{document}
share|improve this question
2  
Can you edit your question to show a complete compilable example rather than a code fragment? See minimal working example (MWE). –  Alan Munn Feb 20 '13 at 17:55
    
@AlanMunn I'm trying to do that. But I'm doing so many changes in the document that it doesn't compile anymore. –  morcillo Feb 20 '13 at 18:13
    
@AlanMunn And I have no idea anymore where things are going to hell. –  morcillo Feb 20 '13 at 18:13
    
So start small, and work your way up. This way you can more easily identify where things have gone wrong. If you get to a point where you have a small change that causes an error, you can post that document and then people can help you. There's not much incentive for people here to do that if you won't yourself. –  Alan Munn Feb 20 '13 at 18:32
1  
@morcillo: It's best if you make a complete minimal example document, starting from \documentclass. It doesn't compile for me if I put it into a document, there seem to be some packages missing. –  Jake Feb 20 '13 at 19:15
show 4 more comments

2 Answers

up vote 4 down vote accepted

I know this post is old but I just figured this out and was too excited not to share...

Pertaining to your first question about bold headers I can offer the following. Before typesetting the table, specify bold font in the column type using

column type={>{\fontseries{bx}\selectfont}c} %see sec 2.6 for defining column types

This should set all entries in your table to bold font. To leave only the headers bold, you can then post-process every cell's content using

postproc cell content/.append style={ % see sec 3.2
/pgfplots/table/@cell content/.add={\fontseries{\seriesdefault}\selectfont}{}}

This works because the second block of code does not apply to header cells, so we can first set everything bold, then reset the other (non-header) cells to normal font. See the sections in comments in the pgfplotstable manual for more information.

Here is a MWE

\documentclass{article}
\usepackage{pgfplotstable}

\begin{document}

\pgfplotstableset{% set global options
format=inline,
string type,
col sep={&}, row sep={\\},
column type={>{\fontseries{bx}\selectfont\centering\arraybackslash}c},
every head row/.style={after row=\hline},
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={\fontseries{\seriesdefault}\selectfont}{}}
}

\pgfplotstabletypeset{% The input table
H1&H2&H3 \\
data1&data2&data3 \\
moredata1&moredata2&moredata3 \\
}

\end{document}

MWE

EDIT:

Here is the code embedded in your formatted table. I commented out the every col no <index>/.style and replaced that block simply with column type={<options>}. This allows you to specify column type for every column. Since you wanted a different specification for the first and last columns, you must manually specify those.

\documentclass{article}
\usepackage{pgfplotstable}
\usepackage{booktabs,colortbl}
\begin{document}
\def\tableborder{1.5pt}

% global settings
\pgfplotstableset{
after row={\hline},
every head row/.style={
before row={
\rowcolor{lightgray}
\noalign{\hrule height \tableborder}
},
after row={
\hline
},
},
every last row/.style={
after row=\noalign{\hrule height \tableborder}
},
col sep = &,
row sep=\\,
% column type/.add={}{\vrule width \tableborder},
%every col no 1/.style={ column type/.add={|}{} },
%every col no 2/.style={ column type/.add={|}{} },
%every col no 3/.style={ column type/.add={|}{} },
%every col no 4/.style={ column type/.add={|}{} },
%every col no 5/.style={ column type/.add={|}{} },
column type={|>{\fontseries{bx}\selectfont}c},
every first column/.style={
column type={!{\vrule width \tableborder}>{\fontseries{bx}\selectfont}c} % removed /.add so you can replace the format rather than append to it.
},
every last column/.style={
column type/.add={}{!{\vrule width \tableborder}}
},
string type,
postproc cell content/.append style={
/pgfplots/table/@cell content/.add={\fontseries{\seriesdefault}\selectfont}{}
}
}


\pgfplotstabletypeset{
person & singEnglish & singGaeilge & pluralEnglish & pluralGaeilge\\
1st & at me & agam & at us & againn\\
2st & at you & agat & at you & agaibh\\
3st & at him & aige & at them & acu\\
& at her & aici & &\\
}
\end{document}

mwe_table_edit

share|improve this answer
    
Nothing against your solution but there should really be a better way to put a font command into every header cell in pgfplotstable. I mean it's a fairly common requirement, isn't it? –  Christian Feb 6 at 12:50
    
This answer hints at a somewhat simpler way to do this: tex.stackexchange.com/a/76338/13450 every head row/.style={typeset cell/.style={...}} But still ... –  Christian Feb 6 at 12:54
    
Ok no, forget it, .style doesn't exist, only .code and there you have to reimplement the default behaviour plus what you'd like it to do (see page 22 of the documentation). Hardly a good way to solve this problem. –  Christian Feb 6 at 13:51
add comment

Ok this isn't a good solution, I really don't like it since it's really speciffic and the intention was to make things easier for the user, but anyway, here it is:

\pgfplotstabletypeset
[columns/col1/.style{column name=\textbf{col1}},
columns/col2/.style{column name=\textbf{col2}},
columns/col3/.style{column name=\textbf{col3}},
columns/col4/.style{column name=\textbf{col4}},
columns/col5/.style{column name=\textbf{col5}}
]{
col1 & col2 & col3 & col4 & col5 \\
1st & at me & agam & at us & againn \\
2st & at you & agat & at you & agaibh \\
3st & at him & aige & at them & acu \\
& at her & aici & & \\
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.