TransWikia.com

How to make cells with the same width in a table?

TeX - LaTeX Asked on February 26, 2021

My question code is as follows:

begin{table}[]
begin{tabular}{|c|c|c|}
hline
multirow{2}{*}{a} & multicolumn{2}{c|}{bcbcbcbc}  cline{2-3} 
                   & d          & e                 hline
end{tabular}
end{table}

The result is as follows:

figure

I want to make d and e boxes the same width.
How can I do that?

2 Answers

This frequently asked question ... Try something like this:

begin{table}[ht]
begin{tabular}{|c|*{2}{>{centeringarraybackslash}p{3em}| }
hline
multirow{2}{*}{a} & multicolumn{2}{c|}{bcbcbcbc}  cline{2-3} 
                   & d          & e                 hline
end{tabular}
end{table}

enter image description here

in preamble you should have

usepackage{array, multirow}

Answered by Zarko on February 26, 2021

Here's a solution that guarantees that the width of the combined header cell -- which currently contains bcbcbcbc, but which presumably is usually more informative -- is minimal, i.e., that the whitespace padding on either edge of the combined cell is equal to tabcolsep. Observe that the solution employs the w column type rather than the c column type for columns 2 and 3; the w column type lets you state a required width.

enter image description here

documentclass{article}
usepackage{multirow,calc}

usepackage{array} % for 'w' column type
newlengthlenA newlengthlenB
% Retrieve the usable width of the combined header cell:
settowidthlenA{bcbcbcbc} 
% Compute the usable width of the underlying columns:
setlengthlenB{(lenA-2tabcolsep-arrayrulewidth)/2} 

begin{document}

begin{table}
begin{tabular}{ | c *{2}{w{c}{lenB}|} }
  hline
  multirow{2}{*}{a} & multicolumn{2}{c|}{bcbcbcbc}  
  cline{2-3} 
                     & d & e  
  hline
end{tabular}
end{table}
end{document}

Answered by Mico on February 26, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP