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.

In the code below, the entries of the first row get stretched across their respective boxes. I get that there's not enough room for each line to fit exactly across the box, but I'd like for it not to spread it across. I'd just like to keep it flush to the left.

\begin{center}
    \small
    \begin{table}[h]
    \centering
    \begin{tabular}{ | p{2.4cm} | p{2.6cm} | p{2.6cm} | p{2.6cm} |   p{2.6cm} | }
    \hline
     & Volume per Longboard ($\mathrm{in}^{3}$) & Mass per Longboard (lb.) & %
                                Volume for 5,000 units & Cost for 5,000 units (\$)\\ \hline
    Polyurethane & 2 & 2 & 2 & 2\\ \hline
    Bamboo & 3 & 3 & 3 & 3\\ \hline
    Aluminum & 4 & 4 & 4 &4\\ \hline
    Steel Alloy & 5 & 5 & 5 & 5\\
    \hline
    \end{tabular}
        \caption{A summary of materials in the longboard with cost calculations.}
    \end{table}
\end{center}
share|improve this question
    
Have you tried loading the tabularx package and specifying \begin{tabularx}{12.8cm}{|*{5}{X|}} ... \end{tabularx}? –  Mico Nov 19 '12 at 4:12
add comment

2 Answers

up vote 5 down vote accepted

You define paragraph columns with a fixed width (why?) which adds up to more horizontal space than the usual article class (for example) provides for \textwidth. (Especially the first p column is questionable, I'd just use the l column here.)

Here some ideas how to improve the table (without changing the cell's or head's content).

Code

\documentclass{article}
%\usepackage{showframe}
\usepackage{graphicx}
\usepackage{booktabs}
\usepackage{tabularx}
\newcolumntype{R}{>{\centering\arraybackslash}X}
\newcommand*{\leftHead}[1]{\multicolumn{1}{>{\raggedright\arraybackslash}X}{#1}}
\newcommand*{\leftHeadV}[1]{\multicolumn{1}{>{\raggedright\arraybackslash}X|}{#1}}
\newcommand{\rotHead}[1]{\rlap{\hspace{-.7em}\rotatebox{45}{#1}}}
\begin{document}
\small
\begin{table}
\centering
\begin{tabular}{lrrrr}
                 & \rotHead{Volume per Longboard ($\mathrm{in}^{3}$)} & \rotHead{Mass per Longboard (lb.)} & \rotHead{Volume for 5,000 units} & \rotHead{Cost for 5,000 units (\$)} \\ \toprule
    Polyurethane &                                                  2 &                                  2 &                                2 &                                   2 \\
    Bamboo       &                                                  3 &                                  3 &                                3 &                                   3 \\
    Aluminum     &                                                  4 &                                  4 &                                4 &                                   4 \\
    Steel Alloy  &                                                  5 &                                  5 &                                5 &                                   5 \\ \bottomrule
\end{tabular}
    \caption{A summary of materials in the longboard with cost calculations.}
\end{table}

\small
\begin{table}
\centering
\begin{tabularx}{\linewidth}{|l|R|R|R|R|}
    \hline
                 & \leftHeadV{Volume per Longboard ($\mathrm{in}^{3}$)} & \leftHeadV{Mass per Longboard (lb.)} & \leftHeadV{Volume for 5,000 units} & \leftHeadV{Cost for 5,000 units (\$)} \\ \hline
    Polyurethane & 2                                                    & 2                                    & 2                                  & 2                                     \\ \hline
    Bamboo       & 3                                                    & 3                                    & 3                                  & 3                                     \\ \hline
    Aluminum     & 4                                                    & 4                                    & 4                                  & 4                                     \\ \hline
    Steel Alloy  & 5                                                    & 5                                    & 5                                  & 5                                     \\ \hline
\end{tabularx}
    \caption{A summary of materials in the longboard with cost calculations.}
\end{table}


\begin{table}
\centering
\begin{tabularx}{\linewidth}{lRRRR}
    \toprule
                 & \leftHead{Volume per Longboard ($\mathrm{in}^{3}$)} & \leftHead{Mass per Longboard (lb.)} & \leftHead{Volume for 5,000 units} & \leftHead{Cost for 5,000 units (\$)} \\ \midrule
    Polyurethane & 2                                                   & 2                                   & 2                                 & 2                                    \\
    Bamboo       & 3                                                   & 3                                   & 3                                 & 3                                    \\
    Aluminum     & 4                                                   & 4                                   & 4                                 & 4                                    \\
    Steel Alloy  & 5                                                   & 5                                   & 5                                 & 5                                    \\ \bottomrule
\end{tabularx}
    \caption{A summary of materials in the longboard with cost calculations.}
\end{table}
\end{document}

Output

enter image description here

share|improve this answer
add comment

as mentioned Mico, try with tabularx, but for left aligned content in cells, you need to define new type of column:

\documentclass{article}
    \usepackage{tabularx}
    \newcolumntype{L}{>{\raggedright\arraybackslash}X}
    \begin{document} 
\begin{table}[h]\small
    \centering
\caption{A summary of materials in the longboard with cost calculations.}
    \begin{tabularx}{133mm}{|l*{4}{|L}| }
    \hline
     & Volume per Longboard ($\mathrm{in}^{3}$) & Mass per Longboard (lb.) & Volume for 5,000 units & Cost for 5,000 units (\$)\\ \hline
    Polyurethane    & 2 & 2 & 2 & 2\\ \hline
    Bamboo          & 3 & 3 & 3 & 3\\ \hline
    Aluminum        & 4 & 4 & 4 & 4\\ \hline
    Steel Alloy     & 5 & 5 & 5 & 5\\
    \hline
    \end{tabularx}    
\end{table}
    \end{document}
share|improve this answer
add comment

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.