5

I have a couple of cvs-files which I want to include with pgfplotstable. Most of the fields are text. The individual columns should be of the type >{\raggedright}p{} for automatic line break and left-aligned text.

The following MWE explains my problem.

\documentclass{scrartcl}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\pgfplotstableset{
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule}
}

\begin{document}
\begin{table}
    \pgfplotstabletypeset[
    col sep=semicolon,string type,
    columns/col1/.style={column type=>{\raggedright}p{.2\textwidth}},
    columns/col2/.style={column type=>{\raggedright}p{.2\textwidth}},
    % columns/col2/.style={column type=p{.2\textwidth}}
    ]
    {
        col1;col2
        long text with multiple lines;long text with multiple lines
    }
\end{table}
\end{document}

Compiling this leads to the following error:

! Misplaced \noalign.
\midrule ->\noalign 
                {\ifnum 0=`}\fi \@aboverulesep =\aboverulesep \global \@...
l.20    }

I expect to see \noalign only after the \cr of
an alignment. Proceed, and I'll ignore this case.

However, if I comment the first line with columns/col2/ out and use the second (commented) line, everything compiles, I just don't get the left alignment for the last column. If there are more columns it's always the last column which causes problems. Does anybody know, how to fix this?

5

Just add \arraybackslash from array package after \raggedright.

For the reason why, the answer to this post: What is \arraybackslash doing on my table column?.

\documentclass{scrartcl}
\usepackage{array}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\pgfplotstableset{
    every head row/.style={before row=\toprule,after row=\midrule},
    every last row/.style={after row=\bottomrule}
}

\begin{document}
    \begin{table}
        \pgfplotstabletypeset[
        col sep=semicolon,string type,
        columns/col1/.style={column type={>{\raggedright\arraybackslash}p{.2\textwidth}}},
        columns/col2/.style={column type={>{\raggedright\arraybackslash}p{.2\textwidth}}},
        ]
        {
            col1;col2
            long text with multiple lines;long text with multiple lines
        }
    \end{table}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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