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 try to set a line break within a tabular environment where the column is not definded with p{$width}. I've tried the following without the expected result

\documentclass{article}
\begin{document}
expected result:

\begin{tabular}{|p{15mm}|l|l|}
\hline
X1\newline{}X2 & text & another text\\\hline
\end{tabular}

real result:

\begin{tabular}{|l|l|l|}
\hline
X1\newline{}X2 (no newline) & a text & another ext\\\hline
\begin{tabular}{l}
X1\\
X2
\end{tabular}
 & a text (not on top) & another text\\\hline
\end{tabular}
\end{document}

Are there any hints?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

put into another tabular:

\documentclass{article}
\def\Stack#1{\tabular[t]{@{}l@{}}#1\endtabular}
\begin{document}
expected result:

\begin{tabular}{|p{15mm}|l|l|}\hline
X1\newline{}X2 & text & another text\\\hline
\end{tabular}

real result:

\begin{tabular}{|l|l|l|}\hline
\Stack{X1\\X2} & a text & another ext\\\hline
\begin{tabular}{@{}l@{}}
X1\\
X2
\end{tabular}
 & a text (not on top) & another text\\\hline
\end{tabular}
\end{document}

enter image description here

share|improve this answer
    
thanks. Is there a possibility to set in one cell a tabular environment on top (like \Stack) and in another a center vertical alignment? –  Micha Feb 19 '13 at 17:29
    
\newcommand\Stack[2][t]{\tabular[#1]{@{}l@{}}#2\endtabular} then \Stack{...} and \Stack[c]{...} is possible. –  Herbert Feb 19 '13 at 17:47

Sorry I misread your tables so the first answer was nonsense.

l columns are like \mbox they do not allow linebreaking. You need to use a p column or nest another structure such as a tabular or parbox in teh cell to allow more than one line, just as you would for \mbox or \fbox

share|improve this answer
    
it does not change the result (using pdflatex TeX-Live 2012) –  Micha Feb 19 '13 at 16:37
    
now I've got the solution: the inner tabular environment has to be set to top: \begin{tabular}[t]{l} –  Micha Feb 19 '13 at 16:45

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.