3

I have tried this piece of code:

\begin{table}[H]
    \centering
    \begin{tabular}{|c|c|c|c|c|c|c|}
    \hline
    \multirow{2}{*}{No.} & \multicolumn{2}{c|}{Initial concentration(M)} & \multirow{2}{*}{\Delta t_1} & \multirow{2}{*}{\Delta t_2} & \multirow{2}{*}{\Delta t_3} & \multirow{2}{*}{\Delta t_{ave}} \\ \cline{2-3}
    & \ch{Na2S2O3} & \ch{H2SO4} & & & & \\ \hline
    
    %%%%%Row 1%%%%%%%%%%
    1 & & & & & & \\ \hline 
    
    %%%%%Row 2%%%%%%%%%%
    2 & & & & & & \\ \hline 
    
    %%%%%Row 3%%%%%%%%%%
    3 & & & & & & \\ \hline 
    \end{tabular}
\end{table}

This is what I got:enter image description here

Clearly, you can see that H2SO4 cell is wider than Na2S2O3 so how can I make those cells equal?

2
  • 1
    Did you try replacing specifiers for columns 2 and 3 with fixed width centred columns?
    – Bernard
    Commented Jul 22, 2022 at 16:41
  • @Bernard No, I'm not. However, I will give it a try. Thanks for your advice. Commented Jul 23, 2022 at 4:44

2 Answers 2

5

If you want (a) columns 2 and 3 to have equal widths and (b) the combined width of columns 2 and 3 to be just large enough to contain the string Initial concentration ($M$), I suggest you proceed as in the first table shown below. The code first measures the width of the string Initial concentration ($M$) and then calculates the usable widths of columns 2 and 3 from this information. The approach employs the w column type, which is provided by the array package.

I would like to encourage you, though, to consider employing a different layout altogether, one with a more open and inviting "look". This may be done in a straightforward manner by getting rid of all vertical lines and using fewer, but well-spaced, horizontal lines with the help the macros of the booktabs package. While you're at it, you could also provide more structure to the headers for columns 4 to 7 and assure that they have equal widths. See the second table for an implementation of these ideas.

enter image description here

\documentclass{article}
\usepackage{mhchem,multirow,calc,array,amsmath,booktabs}
\newlength\mylenA
\newlength\mylenB
\newlength\mylenC

\begin{document}
\begin{table}[th]
% determine target width of combined cols 2 and 3:
\settowidth\mylenA{Initial concentration ($M$)} 
% determine usable width of cols 2 and 3:
\setlength\mylenB{(\mylenA-2\tabcolsep)/2}

    \centering
    \begin{tabular}{| c | *{2}{wc{\mylenB}|} c | c | c | c |}
    \hline
    \multirow{2}{*}{No.} & 
    \multicolumn{2}{c|}{Initial concentration ($M$)} & 
    \multirow{2}{*}{$\Delta t_1$} & 
    \multirow{2}{*}{$\Delta t_2$} & 
    \multirow{2}{*}{$\Delta t_3$} & 
    \multirow{2}{*}{$\Delta t_{\mathrm{ave}}$} \\ 
    \cline{2-3}
    & \ce{Na2S2O3} & \ce{H2SO4} & & & & \\ \hline
    1 & & & & & & \\ \hline 
    2 & & & & & & \\ \hline 
    3 & & & & & & \\ \hline 
    \end{tabular}
\end{table}

%% same table, but with well-spaced horizontal rules and no vertical rules:
\begin{table}[h]
% determine target usable width of combined cols 2 and 3:
\settowidth\mylenA{Initial concentration ($M$)} 
% determine usable width of cols 2 and 3:
\setlength\mylenB{(\mylenA-2\tabcolsep)/2}
% set target width of cols 4 thru 7:
\settowidth\mylenC{avg.}
    \centering
    \begin{tabular}{@{} l *{2}{wc{\mylenB}} *{4}{wc{\mylenC}} @{}}
    \toprule
    No. & 
    \multicolumn{2}{c}{Initial concentration ($M$)} & 
    \multicolumn{4}{c@{}}{$\Delta t$} \\
    \cmidrule(lr){2-3} \cmidrule(l){4-7}
    & \ce{Na2S2O3} & \ce{H2SO4} & 1 & 2 & 3 & avg. \\ \midrule
    1 & & & & & & \\ \addlinespace
    2 & & & & & & \\ \addlinespace
    3 & & & & & & \\ \bottomrule
    \end{tabular}
\end{table}
\end{document}
3
  • 1
    \settowidth should go inside the table environment. For sure not in the preamble, where \normalfont has not yet been issued. And maybe the tabular requires \small… Or, maybe, one wants to change the header text…
    – egreg
    Commented Jul 22, 2022 at 21:30
  • @egreg - Thanks for these suggestions. I've updated my answer accodingly.
    – Mico
    Commented Jul 22, 2022 at 22:20
  • 1
    Thank you guys for helping me. Commented Jul 23, 2022 at 4:42
0

With {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{nicematrix}
\usepackage{mhchem}

\begin{document}

\NiceMatrixOptions{ampersand-in-blocks}
\renewcommand{\arraystretch}{1.2}

\begin{NiceTabular}[hvlines]{ccccccc}
\Block{2-1}{No.} & Initial concentration (M) & \Block{2-1}{$\Delta t_1$} & 
\Block{2-1}{$\Delta t_2$} & 
\Block{2-1}{$\Delta t_3$} & 
\Block{2-1}{$\Delta t_{\text{ave}}$} \\
  & \Block{}{\ce{Na2S2O3}& \ce{H2SO4}} \\
1 & \Block{}{&} \\
2 & \Block{}{&} \\
3 & \Block{}{&} \\
\end{NiceTabular}

\end{document}

Output of the above code

You must log in to answer this question.

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