Tell me more ×
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.

This question may look like a duplicate but, none of the answers given to the possible duplicates contain the answer to this specific case.

I have a tabular, say \begin{tabular}{ccc}. While adding a new line to a cell, I want both resulting lines to be horizontally centered. Is there an elegant solution to this? If not is there a solution to this?

share|improve this question

3 Answers

up vote 9 down vote accepted

How about using \shortstack inside a cell?

\documentclass{article}

\begin{document} 
\begin{tabular}{ccc}
    one & two & three \\
    one & two & \shortstack{a \\ bb \\ c}\\
\end{tabular}
\end{document}
share|improve this answer
Well, this worked like a charm, why didn't I see anyone mentioning this before? Simple, straightforward solution. – nimcap Dec 20 '11 at 15:55
1  
+1 for \shortstack. – Philipp Dec 20 '11 at 16:11
6  
+1 And to align the content, use \shortstack[r]{...} (r = right align, l = left align, c = center align). – Rob W May 14 '12 at 10:52
1  
Very cool, thanks! – sharky Jul 17 '12 at 7:58

If you want the cells to be centered horizontally as well as vertically I suggest the following solution:

\documentclass{article}
\usepackage{booktabs}
\newcommand{\bigcell}[2]{\begin{tabular}{@{}#1@{}}#2\end{tabular}}

\begin{document} 

\begin{tabular}{ccc}
\toprule
a & \bigcell{c}{this schould be a longer line \\ this is a shorter one} & c \\ 
\midrule
 0,9892 & 0,9892 & 0,9892  \\
\end{tabular}

\end{document}
share|improve this answer

Another way I discovered is to use matrix. Not as simple as Christian's answer but provides vertical alignment along columns.

\documentclass{article}
\usepackage{amsmath}

\begin{document} 
\begin{tabular}{ccc}
    one & two & three \\
    one & two & $\begin{matrix} \text{a} \\ \text{bb} \\ text{c} \end{matrix}$ \\
\end{tabular}
\end{document}
share|improve this answer

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.