4

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?

1

2 Answers 2

8

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
\newlength\lenA \newlength\lenB
% Retrieve the usable width of the combined header cell:
\settowidth\lenA{bcbcbcbc} 
% Compute the usable width of the underlying columns:
\setlength\lenB{(\lenA-2\tabcolsep-\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}
1
  • 4
    Now i see I'm getting old. it's getting harder and harder to remember the new array's column specification options :-(. Nice answer (+1)
    – Zarko
    Dec 19, 2020 at 23:39
6

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

\begin{table}[ht]
\begin{tabular}{|c|*{2}{>{\centering\arraybackslash}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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .