2

I'm trying to construct a table that looks like the following:

enter image description here

I know I need to use multirow package in the tabular environment, but I can't figure out how since I couldn't find examples that are similar to my need. It seems like I need to use a multicolumn environment inside multirow for the 'Experiment' cells.

Can someone guide me in the right direction? Thank you!

2 Answers 2

2
\begin{tabular}{|c|cc|cc|}
\hline \hline \multirow{2}{*}{ Parameter } & \multicolumn{2}{|c|}{ Experiment 1 } & \multicolumn{2}{|c|}{ Experiment 2 } \\
\cline { 2 - 5 } & Mean & Std & Mean & std \\
\hline \hline B $[\mathrm{m}]$ & 2.5 & 1.03 & 4.5 & 0.9 \\
\hline
\end{tabular}

Make sure you use in the preamble:
\usepackage{multirow}

Here is the output: Latexouputtable

1
  • +1. Just in case the OP also loads the array package (or some other package, such as tabularx, which loads the array package automatically), you should change both instances of \multicolumn{2}{|c|} to \multicolumn{2}{c|}. Again, the outcomes are the same if array is not loaded. However, this condition is not one one may reasonably assume to hold, especially as the array package is among the most frequently loaded of all packages.
    – Mico
    Nov 19, 2023 at 0:17
4

Another possibilities is to use tabularray packages for writing your table- Using it resulted table is to my opinion more nice.

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{tblr}{hlines, vlines,
                 colspec      = {c *{4}{Q[c, wd=3em]}},
                 cell{1}{1}   = {r=2}{},
                 cell{1}{2,4} = {c=2}{}
                 }
Parameter       &   Experiment 1    &       &   Experiment 2    &       \\
                & Mean              & Std   & Mean              & Std   \\
B [\unit{\m}]   & 2.5               & 1.03  & 4.5               & 0.9   \\
    \end{tblr}
\end{document}

enter image description here

However, it is not clear if your code fragment contain complete table or your real table has several rows. In the second case, you may consider to draw only horizontal lines only in column headers and at the end of table and for numbers aligning in columns use siunitx package. For example:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{tblr}{colspec      = {c *{4}{Q[c, wd=3em, si={table-format=1.2}]}},
                 cell{1}{1}   = {r=2}{},
                 cell{1}{2,4} = {c=2}{},
                 row{1,2} = {guard}
                 }
    \toprule
Parameter       &   Experiment 1    &       &   Experiment 2    &       \\
    \cmidrule[lr]{2-3}
    \cmidrule[l]{4-5}
                & Mean              & Std   & Mean              & Std   \\
    \midrule
B [\unit{\m}]   & 2.5               & 1.03  & 4.5               & 0.9   \\
C [\unit{\m}]   & 1.5               & 1.1   & 4.55              & 0.89  \\
    \bottomrule
    \end{tblr}
\end{document}

which gives more "professional" looks of table:

enter image description here

2
  • This indeed looks great! However I'm using Overleaf and can't load the tabularray package sadly. Nov 19, 2023 at 1:29
  • Overleaf has support for tabularray package (I tested it in Overleaf). However, you should start new document, in which you insert your old document, load tabularray package and my suggested table code. If you will problems with this, ask Overleaf support for help.
    – Zarko
    Nov 19, 2023 at 2:15

You must log in to answer this question.

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