1

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:

enter image description here

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

2
  • 1
    search for \mbox Commented Sep 21, 2019 at 11:58
  • 1
    @Surb I can't think of any way \mbox would help with this question Commented Sep 21, 2019 at 12:10

1 Answer 1

2

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\theadalign{cb} \renewcommand\theadfont{\bfseries} \renewcommand\theadgape{\Gape[4pt]} \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} % \qquad % \setlength{\extrarowheight}{3pt} \begin{tabular}{|>{\centering}m{20mm}|>{\centering\arraybackslash}m{20mm} !{\vrule width2.5pt}} \hline multi-lined \newline contents & single line \\ \Xhline{2.5pt} \end{tabular} \end{document} 

enter image description here

2
  • 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. Commented Sep 21, 2019 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. Commented Sep 21, 2019 at 13:34

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.