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 had a problem putting the column headers in bold (in a table of course) using pgfplotstable. You can see the problem here I found a way to work arround that. It isn't generic as I wanted it to be, but at least I know there is a way to do it.

The only thing I had to do was to add options to the table when creating it, just like this:

\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 & & \\
}

As you can see it's not the best way to do things, especially when you're new to latex and trying to introduce people to latex, people who've never used latex before. That's the reason why I wanted to create a macro for all those options so that the others should simply add \mymacro(column1name, column2name, ...) to the side of the \pgfplotstabletypeset to make everything easier.

I tried this:

\newcommand\mymacro[3]{    % 3 is just an example, I did \mymacroone .. two ..                    %etc in order to be able to apply the same concept in different situations
columns/#1/.style{column name=\textbf{#1}},
columns/#2/.style{column name=\textbf{#2}},
columns/#3/.style{column name=\textbf{#3}}
}

But this jut generates an error and (can't use # in horizontal mode) doesn't compile. Does anyone know of a better way to do this, or how I can correct the expression to make iot compilable? I tried using {#}, #, {#}, ##, but haven't been able to do it right.

share|improve this question
2  
Can you turn the snippet of code into a full minimal example? Add also the proposed code that doesn't work. –  egreg Feb 21 '13 at 22:21
    
@egreg I'll do it tomorrow morning first thing. I left it all at work. –  morcillo Feb 21 '13 at 22:44
    
@egreg But you can find a full code snippet in the question linked in this question's description. Just click the link on the word "here" in the desciption and you will get a code snippet. –  morcillo Feb 21 '13 at 22:45
    
I tried to follow the link but if I insert the code in the question I get: Argument of \reserved@a has an extra }. <inserted text> \par l.48 ] { ? –  David Carlisle Feb 21 '13 at 23:02
    
@DavidCarlisle That is another comoilation error that appears some times. I just can't use \mymacro. It just fails –  morcillo Feb 21 '13 at 23:05

1 Answer 1

up vote 6 down vote accepted

enter image description here

\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,
}


\newcommand\mymacro[5]{%
[columns/col1/.style={column name=\textbf{#1}},
columns/col2/.style={column name=\textbf{#2}},
columns/col3/.style={column name=\textbf{#3}},
columns/col4/.style={column name=\textbf{#4}},
columns/col5/.style={column name=\textbf{#5}}]}

\begin{document}


\expandafter\pgfplotstabletypeset\mymacro{red}{blue}{green}{yellow}{pink}
{
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 & & \\
}
\end{document}
share|improve this answer
    
Thank you very much for going through the problem of fixing my mistakes (been in latex only for a month). But I have a question. That only generates a table with col1, col2, and so on, it doesn't allow me to put any column name I want. Or does it? Sorry for any english mistakes –  morcillo Feb 21 '13 at 23:45
    
@morcillo sorry posted wrong version, try now –  David Carlisle Feb 21 '13 at 23:50
    
Thank you. You're a genious (not sure if it's spelled this way) –  morcillo Feb 22 '13 at 12:51

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.