# Issue

How can I specify the column width without explicitly knowing how many columns there will be in my table?

In the pgfplotstable manual Revision 1.12 (2015/01/31) on page 35, there is a section about typesetting. One of the pictures looks like this (also with a nice overfull line, :D ):

The line

\begin{tabular}{ccc}%

I would like to effectively make into

\begin{tabular}{p{.4\textwidth}ll}

BUT Using pgfplotstable macros.

Caveat: I do not know how many columns there are (working with a global definition for many tables that have varying numbers of columns). This means I'd really like an answer that allows more abstraction from the standard commands.

# Ideas

If I wanted to make the first column have a specific width, say 40% of main text box, I would have a few options.

All of the ways I know how to do this are:

\begin{minipage}{.4\textwidth}
some cell text
\end{minipage}

\parbox{.4\textwidth}{%
some cell text
}%

\begin{tabular}{ p{.4\textwidth} }
some cell text
\end{tabular}


# Pseudo Solution

every column 0/.style={postproc cell content/.style={@cell content=\parbox{.4\textwidth}{##1}}},


# Example Code

\documentclass{article}
\usepackage{fontspec}
\usepackage{booktabs}
\usepackage{pgfplotstable}
\pgfplotstableset{% Global config
every last row/.style={after row=\bottomrule},
col sep=&,
row sep=\\,
column type=l,
column type={>{\fontseries{bx}\selectfont\color{orange}}l}, %see sec 2.6 for defining column types
string type,
postproc cell content/.append style={ % see sec 3.2
}%

\begin{document}
\pgfplotstabletypeset{%
col1 & col2 & col3\\
here & more & stuff\\
for & good & looks\\
}%
\end{document}

• I think your title doesn't match what you want to achieve. Apr 3, 2015 at 10:31
• @percusse I see why you might think so. I wrote my question this way because it is was intention to wrap text in cells—ultimately the goal of the question (I could have asked "How can I set the width of arbitrary columns in pgfplotstable?") Your example does not actually show any text being wrapped, although it does function that way. I will leave the question as is unless you can provide a reasonably strong argument to the contrary. Apr 4, 2015 at 14:58
• Your issue is to change the column type as you wrote introduction yourself. And you have an idea about how to achieve that. Your solution is not changing the column type but faking it with changing its width which is clearly not changing the column type. Hence my comment. Apr 4, 2015 at 15:04
• To me, the title is misleading as well. I have text in the last column of the table which does not fit on a single line. And the answer posted by @percusse does not wrap the content of the cell after the specified size but lets the text grow out of the page. May 24, 2016 at 14:04

If you know the name or the number of the column you can specify only that property and the rest will still assume c so you don't need the number of columns.

\documentclass{article}
\usepackage{booktabs}
\usepackage{pgfplotstable}

\begin{document}
\pgfplotstabletypeset[
string type,
display columns/0/.style={column type={p{.4\textwidth}}},% columns/col1/.style also works
col sep=&,row sep=crcr,
]{%
col1 & col2 & col3\\
here & more & stuff\\
for & good & looks\\
}%
\end{document}


• Say, the entry in col3 is not only stuff but stuffThatIsReallyToLong which does not fit in a single line. Is there a way to really wrap the text of col3 by creating a higher cell? Or should this be a separate question. May 24, 2016 at 14:06
• This works nicely in a similar case for me. Thanks a lot... made my evening. Jul 16, 2017 at 21:14
• @MWiesner Pleasure is mine. Jul 16, 2017 at 21:40