0

I am using a straight-forward \pgfplotstabletypeset.

Because I wanted to insert a manual break in one of the cells to decrease the width of that cell, I added a \pbox as suggested in https://tex.stackexchange.com/a/11555

The problem is that the resulting height is a little bit too small for my taste: table

As you can see, "some" is at the very top of the cell and "text" at the very bottom. I'd like to have a small extra space at the top and at the bottom.

I was not able to achieve this with the stuff I tried.

Any ideas?

Here is the minimal working example that shows the problem:

\documentclass[11pt,a4paper]{article}

\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotstableset{
    column type=l,
    every head row/.style={
    before row=\toprule,
    after row=\midrule},
    every even row/.style={before row={\rowcolor[gray]{0.85}}},
    every odd row/.style={before row={\rowcolor[gray]{0.95}}},
    every last row/.style={
    after row=\bottomrule},
    col sep = &,
    row sep=\\,
    string type,
}

\usepackage{pbox}

\begin{document}
\begin{table}[h]
\pgfplotstabletypeset{
a & b \\
1 & 2 \\
\pbox[c]{20cm}{some \\ long \\ text} & foo \\
3 & 4 \\
}
\end{table}
\end{document}

Bernard, thank you for your suggestion that you posted below.

There is a problem, however, when longer lines are present in the table.

Please add the following row to the minimal working example that you posted:

\makecell{some even longer \\ text that spans \\ three lines}  & foo \\

This will result in the following table:

enter image description here

You said that the same resulting table can be obtained without pgfplotstable. That's fine with me - If you have a suggestion how to do it differently, I'm open to use that as well.

Note to Paul Gaborit: I posted my original question as an anonymous user, so I cannot comment on my own or any other comment when I come back to this page, or?

  • Trouble accessing your account? – T. Verron Dec 23 '14 at 9:31
1

You can use the makecell package, instead of \pbox: this package allows for linebreaks in table cells with its \makecell, \thead, \rotcell and \rothead commands:

\documentclass[11pt,a4paper]{article}

\usepackage{booktabs}
\usepackage{colortbl}
\usepackage{pgfplotstable}
\pgfplotstableset{
    column type=l,
    every head row/.style={
    before row=\toprule,
    after row=\midrule},
    every even row/.style={before row={\rowcolor[gray]{0.85}}},
    every odd row/.style={before row={\rowcolor[gray]{0.95}}},
    every last row/.style={
    after row=\bottomrule},
    col sep = &,
    row sep=\\,
    string type,
}

\usepackage{makecell}
\renewcommand\cellalign{lc}

\begin{document}
\begin{table}[h]
\pgfplotstabletypeset{
a & b \\
1 & 2 \\
\makecell{some \\ long \\ text} & foo \\
3 & 4 \\
}
\end{table}
\end{document} 

enter image description here

Comment aside: you can obtain the same resulting table without using pgfplotstable.

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.