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 have a table of maths as below, where I've used the p{} attribute to allow the list of partitions to wrap inside the cell. The problem is that it also justifies the column, which looks very strange for the rows 6-10 because you get huge gaps. What I want is the list of partitions to be left-justified with standard spacing, like in the first few rows, but still able to spill over onto multiple rows.

\usepackage{amsmath}

\begin{document}

\begin{table}
\renewcommand{\arraystretch}{1.3}
 \begin{center}
 \label{pntable}
 \begin{tabular}{|c|p{6.5cm}|c|}
 \hline
 \textbf{Integer} & \textbf{Partitions} & \textbf{Number of partitions} \\ \hline
 1 & 1 & 1 \\ \hline
 2 & 2, 1+1 & 2 \\ \hline
 3 & 3, 2+1, 1+1+1 & 3 \\ \hline
 4 & 4, 3+1, 2+2, 2+1+1, 1+1+1+1 & 5 \\ \hline
 5 & 5, 4+1, 3+2, 3+1+1, 2+2+1, 2+1+1+1, 1+1+1+1+1 & 7 \\ \hline
 6 & 6, 5+1, 4+2, 4+1+1, 3+3, 3+2+1, 3+1+1+1, 2+2+2, 2+2+1+1, 2+1+1+1+1, 1+1+1+1+1+1 & 11 \\ \hline
 7 & 7, 6+1, 5+2, 5+1+1, 4+3, 4+2+1, 4+1+1+1, 3+3+1, 3+2+2, 3+2+1+1, 3+1+1+1+1, 2+2+2+1, 2+2+1+1+1, 2+1+1+1+1+1, 1+1+1+1+1+1+1 & 15 \\ \hline
 8 & 8, 7+1, 6+2, 6+1+1, 5+3, 5+2+1, 5+1+1+1, 4+4, 4+3+1, 4+2+2, 4+2+1+1, 4+1+1+1+1, 3+3+2, 3+3+1+1, 3+2+2+1, 3+2+1+1+1, 3+1+1+1+1+1, 2+2+2+2, 2+2+2+1+1, 2+2+1+1+1+1, 2+1+1+1+1+1+1, 1+1+1+1+1+1+1+1 & 22 \\ \hline
 9 & 9, 8+1, 7+2, 7+1+1, 6+3, 6+2+1, 6+1+1+1, 5+4, 5+3+1, 5+2+2, 5+2+1+1, 5+1+1+1+1, 4+4+1, 4+3+2, 4+3+1+1, 4+2+2+1, 4+2+1+1+1, 4+1+1+1+1+1, 3+3+3, 3+3+2+1, 3+3+1+1+1, 3+2+2+2, 3+2+2+1+1, 3+2+1+1+1+1, 3+1+1+1+1+1+1, 2+2+2+2+1, 2+2+2+1+1+1, 2+2+1+1+1+1+1, 2+1+1+1+1+1+1+1, 1+1+1+1+1+1+1+1+1 & 30 \\ \hline
 10 & 10, 9+1, 8+2, 8+1+1, 7+3, 7+2+1, 7+1+1+1, 6+4, 6+3+1, 6+2+2, 6+2+1+1, 6+1+1+1+1, 5+5, 5+4+1, 5+3+2, 5+3+1+1, 5+2+2+1, 5+2+1+1+1, 5+1+1+1+1+1, 4+4+2, 4+4+1+1, 4+3+3, 4+3+2+1, 4+3+1+1+1, 4+2+2+2, 4+2+2+1+1, 4+2+1+1+1+1, 4+1+1+1+1+1+1, 3+3+3+1, 3+3+2+2, 3+3+2+1+1, 3+3+1+1+1+1, 3+2+2+2+1, 3+2+2+1+1+1, 3+2+1+1+1+1+1, 3+1+1+1+1+1+1+1, 2+2+2+2+2, 2+2+2+2+1+1, 2+2+2+1+1+1+1, 2+2+1+1+1+1+1+1, 2+1+1+1+1+1+1+1+1, 1+1+1+1+1+1+1+1+1+1 & 42 \\ \hline
 \end{tabular}
 \end{center}
 \caption{All the partitions of $n \in \{1,\ldots,10\}$}
\end{table}

\end{document}

Apologies in advance because I'm sure this will have been answered before, but I can't find it anywhere and really need some help!

share|improve this question

2 Answers 2

use the array package then you can use

\begin{tabular}{|c|>{\raggedright}p{6.5cm}|c|}
share|improve this answer

Since the second column has math expressions, you can use the >{...}, <{...} construct from the array package, not only to get the left justification, but to change to math mode inside this column (it is not the same thing to write 3+4 in text mode than $3+4$). Your table format definition could be something like

\begin{tabular}{c>{\raggedright\arraybackslash$}p{6.5cm}<{$}c}

As a side note, I would suggest you to use the booktabs package to build your tables. Here's an example of your table:

\documentclass[a4paper,twoside]{book}

\usepackage{amsmath}
\usepackage{array}
\usepackage{booktabs}

\begin{document}

\begin{table}
 \centering
 \label{pntable}
 \begin{tabular}{c>{\raggedright\arraybackslash$}p{6.5cm}<{$}c}
 \toprule
 \textbf{Integer} & \textbf{Partitions} & \textbf{Number of} \\
 & &  \textbf{partitions} \\ \midrule
 1 & 1 & 1 \\ \midrule
 2 & 2, 1+1 & 2 \\ \midrule
 3 & 3, 2+1, 1+1+1 & 3 \\ \midrule
 4 & 4, 3+1, 2+2, 2+1+1, 1+1+1+1 & 5 \\ \midrule
 5 & 5, 4+1, 3+2, 3+1+1, 2+2+1, 2+1+1+1, 1+1+1+1+1 & 7 \\ \midrule
 6 & 6, 5+1, 4+2, 4+1+1, 3+3, 3+2+1, 3+1+1+1, 2+2+2, 2+2+1+1, 2+1+1+1+1, 1+1+1+1+1+1 & 11 \\ \midrule
 7 & 7, 6+1, 5+2, 5+1+1, 4+3, 4+2+1, 4+1+1+1, 3+3+1, 3+2+2, 3+2+1+1, 3+1+1+1+1, 2+2+2+1, 2+2+1+1+1, 2+1+1+1+1+1, 1+1+1+1+1+1+1 & 15 \\ \midrule
 8 & 8, 7+1, 6+2, 6+1+1, 5+3, 5+2+1, 5+1+1+1, 4+4, 4+3+1, 4+2+2, 4+2+1+1, 4+1+1+1+1, 3+3+2, 3+3+1+1, 3+2+2+1, 3+2+1+1+1, 3+1+1+1+1+1, 2+2+2+2, 2+2+2+1+1, 2+2+1+1+1+1, 2+1+1+1+1+1+1, 1+1+1+1+1+1+1+1 & 22 \\ \midrule
 9 & 9, 8+1, 7+2, 7+1+1, 6+3, 6+2+1, 6+1+1+1, 5+4, 5+3+1, 5+2+2, 5+2+1+1, 5+1+1+1+1, 4+4+1, 4+3+2, 4+3+1+1, 4+2+2+1, 4+2+1+1+1, 4+1+1+1+1+1, 3+3+3, 3+3+2+1, 3+3+1+1+1, 3+2+2+2, 3+2+2+1+1, 3+2+1+1+1+1, 3+1+1+1+1+1+1, 2+2+2+2+1, 2+2+2+1+1+1, 2+2+1+1+1+1+1, 2+1+1+1+1+1+1+1, 1+1+1+1+1+1+1+1+1 & 30 \\ \midrule
 10 & 10, 9+1, 8+2, 8+1+1, 7+3, 7+2+1, 7+1+1+1, 6+4, 6+3+1, 6+2+2, 6+2+1+1, 6+1+1+1+1, 5+5, 5+4+1, 5+3+2, 5+3+1+1, 5+2+2+1, 5+2+1+1+1, 5+1+1+1+1+1, 4+4+2, 4+4+1+1, 4+3+3, 4+3+2+1, 4+3+1+1+1, 4+2+2+2, 4+2+2+1+1, 4+2+1+1+1+1, 4+1+1+1+1+1+1, 3+3+3+1, 3+3+2+2, 3+3+2+1+1, 3+3+1+1+1+1, 3+2+2+2+1, 3+2+2+1+1+1, 3+2+1+1+1+1+1, 3+1+1+1+1+1+1+1, 2+2+2+2+2, 2+2+2+2+1+1, 2+2+2+1+1+1+1, 2+2+1+1+1+1+1+1, 2+1+1+1+1+1+1+1+1, 1+1+1+1+1+1+1+1+1+1 & 42 \\ \bottomrule
 \end{tabular}
 \caption{All the partitions of $n \in \{1,\ldots,10\}$}
\end{table}

\end{document}

enter image description here

share|improve this answer
    
Thank you so much, that's extremely helpful! –  Michael Apr 19 '12 at 9:06

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.