3

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?

0

2 Answers 2

4

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

2
  • 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, 2013 at 17:29
  • \newcommand\Stack[2][t]{\tabular[#1]{@{}l@{}}#2\endtabular} then \Stack{...} and \Stack[c]{...} is possible.
    – user2478
    Feb 19, 2013 at 17:47
1

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

2
  • it does not change the result (using pdflatex TeX-Live 2012)
    – Micha
    Feb 19, 2013 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, 2013 at 16:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.