# Horizontally and vertically centered multi-lined cells

I want a table where the cells contain either a single line of text or two lines of text, and the cell contents are both horizontally and vertically centered.

The height of the cells should be 2cms and length 3cms (assuming the text does not overflows), and some of the cell boundaries should be bold.

One example is as follows:

Any help to create such a table in latex would be much appreciated. Thank You.

• search for \mbox – Surb Sep 21 '19 at 11:58
• @Surb I can't think of any way \mbox would help with this question – David Carlisle Sep 21 '19 at 12:10

Here are two ways, depending on whether you have fixed width cells or not:

• for a standard cell (column specifier r, l or c), you can use the makecell command,
• for a fixed width cell, use the m{some length} column type

A demo of both:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{fourier}
\usepackage{array}
\usepackage{makecell}

\renewcommand\cellgape{\Gape[4pt]}

\begin{document}

\sffamily
\begin{tabular}{ | c | c !{\vrule width2.5pt}}
\hline
\makecell{multi-lined \\ contents} & single line \\
\Xhline{2.5pt}
\end{tabular}
%

• Thank you for your answer. I am wondering if the space between the two lines 'multi-lined' and 'contents' can be reduced? Also, if I increase the height of the cell for the first option, like \renewcommand\cellgape{\Gape[10pt]}, both the lines move far apart, can this be reduced? And in the second option, if I increase the height by \setlength{\extrarowheight}{20pt} the lines are placed towards the bottom of the cell instead of the center. – user197878 Sep 21 '19 at 13:02
• Actuallt \cellgape adds this amount of vertical space at the top and bottom of cells, so this is the normal behaviour . Another solution, valid for both methods, use the cellspace package which ensures a minimal vertical spacing at top and bottom of cells in columns with specifier prefixed with the letter S (or C if you also load siunitx). For instance, here, you might use as tables preambles {|Sc|Sc!{\vrule width 2.5pt} and {|>{\centering}S{m{20mm}}|>{\centering\arraybackslash}S{m{20mm} }!{\vrule width2.5pt}} respectively. – Bernard Sep 21 '19 at 13:34