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.

A while ago I had a question about having multi-line strings in a table cell ( http://tex.stackexchange.com/questions/3748/in-cell-newlines-in-tabular-environments).

I remember seeing it working but I've just tried to use it again and ... \newline did nothing.

A test LaTeX source is below, which, despite the \newline commands, it did not split the cells on multiple lines:

alt text

\documentclass[12pt,titlepage]{article}
\RequirePackage[l2tabu,orthodox]{nag}
\usepackage[english]{babel}
\usepackage{pslatex}
\usepackage{setspace}
\setstretch{1.6}
\usepackage{booktabs}
\usepackage[final,babel]{microtype}
\usepackage[detect-all]{siunitx}
\setlist{nolistsep}
\frenchspacing

\begin{table}[htp]
    \centering
    \begin{tabular}{@{}l l l l@{}}
          \toprule
           & \textbf{Foo} & {\textbf{Bar}} & \textbf{Baz} \\
          \midrule
            \textbf{Single line} & foo1 foo2 & bar1 bar2 & baz1 baz2 \\
            \textbf{Multiline} & foo1 \newline foo2 & bar1 \newline bar2 & baz1 \newline baz2 \\
          \bottomrule
    \end{tabular}
    \caption {\small{bla bla}}\label{my-label}
\vspace*{-3mm}
\end{table}

Thanks in advance.

share|improve this question
    
Far from minimal example, and nothing to do with booktabs. –  Lev Bishop Oct 18 '10 at 3:52
    
I put the packages that I thought might influence it (and thought booktabs was used since it's imported). Sorry about \vspace, I missed it when editing the real table. –  wishihadabettername Oct 18 '10 at 4:08
1  
You should have tried which of the packages influence it before posting the question... –  Jukka Suomela Oct 18 '10 at 12:21
add comment

1 Answer

up vote 6 down vote accepted

Use tabular p specifier instead of l.

\documentclass{article}
\begin{document}
\begin{tabular}{@{}l p{2cm}p{3cm}p{3cm}@{}}
    & \textbf{Foo} & {\textbf{Bar}} & \textbf{Baz} \\
    \textbf{Single line} & foo1 foo2 & bar1 bar2 & baz1 baz2 \\
    \textbf{Multiline} & foo1 \newline foo2 & bar1 \newline bar2 & baz1 \newline baz2 \\
\end{tabular}
\end{document} 
share|improve this answer
    
it doesn't work. I had tried it before posting, I got "Missing number, treated as zero" on the line declaring the table header.My tabular declaration was \begin{tabular}{@{}p p p p@{}} –  wishihadabettername Oct 18 '10 at 4:09
    
The format is p{length}. Minimal example attached. –  Lev Bishop Oct 18 '10 at 4:17
    
Thank you, Lev. –  wishihadabettername Oct 18 '10 at 11:31
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.