# \flushleft with p{} option in tabular

If I have defined tabular alignment with the p{} option,

\begin{tabular}{p{.3\textwidth}p{.7\textwidth}}
...(contents)...
\end{tabular}


Is there a way to specify that I want it \flushleft without wrapping the contents of each cell in a \parbox or minipage environment? It might be trouble in the example above, but I have dozens of cells, so is not a very feasible solution (unless I program something with Emacs Lisp).

-

Load the array package and write

\begin{tabular}{>{\raggedright}p{.3\textwidth}
>{\raggedright\arraybackslash}p{.6\textwidth}}


It's necessary to use the \arraybackslash in the last column, otherwise \\ would not end the table row. You can use \newline to end lines in the last column cells (and the regular \\ in the other column cells).

By the way, a tabular specification like yours will give an overfull box, as you are not keeping into account the intercolumn spaces. If you want that the table extends all the way of the line width, say

\begin{tabular}{@{}>{\raggedright}p{.3\textwidth-\tabcolsep}
>{\raggedright\arraybackslash}p{.7\textwidth-\tabcolsep}@{}}


\begin{tabular}{@{}
>{\raggedright}
p{\dimexpr.3\textwidth-\tabcolsep\relax}
>{\raggedright\arraybackslash}
p{\dimexpr.7\textwidth-\tabcolsep\relax}@{}}


The two @{} avoid the insertion of the intercolumn space before and after the tabular.

-
I like to define something like \def\myraggedright{\rightskip0mm plus10mm\relax} and use that instead of \raggedright in the column definition. This way you have the text flushed left without the large space between words, but with hyphenation, so that the output looks much less ragged than with \raggedright. –  Elmar Zander Jan 10 '12 at 13:44
@ElmarZander You can also use the ragged2e package and its \RaggedRight command that does something similar to yours. –  egreg Jan 10 '12 at 14:01

You could use a feature of the array package to insert a \raggedright command for flush left text, use >{command} before the column definition to insert one or several command(s):

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{array}
\begin{document}
\begin{tabular}{>{\raggedright\arraybackslash}p{.3\textwidth}p{.7\textwidth}}
\blindtext & \blindtext
\end{tabular}
\end{document}


You mentioned \flushleft - you could use it but it can insert undesired vertical space, such as

\begin{tabular}{>{\flushleft\arraybackslash}p{.3\textwidth}<{\endflushleft}p{.7\textwidth}}


If you need it often, consider defining a new column type using array features, as I did here:

\newcolumntype{P}[1]{>{\raggedright\arraybackslash}p{#1}}


Some people define further useful types, such as

\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}


etc. So your tabular definition becomes simpler:

\begin{tabular}{P{.7\textwidth}P{.3\textwidth}}


In narrow columns, it may be good to allow hyphenation. This can be done using ragged2e. microtype could improve even more. So I would use:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{blindtext}
\usepackage{array}
\usepackage{ragged2e}
\usepackage{microtype}
\newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
\begin{document}
\begin{tabular}{P{.7\textwidth}P{.3\textwidth}}
\blindtext & \blindtext \\
\end{tabular}
\end{document}


With ragged2e commands \arraybackslash is not needed. As the first word in a box would not be hyphenated, I additionally inserted zero horizontal space.

-
\arraybackslash is necessary only in the last column. –  egreg Oct 13 '11 at 23:30
Still works with it though... and I like the convenience of having a new column type! –  crippledlambda Oct 15 '11 at 11:36