TransWikia.com

Creating tables with spanning rows/columns

TeX - LaTeX Asked by Nishant on May 14, 2021

I’m trying to create a table which looks like

this

but I’m not really sure how to incorporate multiple spanning rows and columns together (to add ‘Organism 1’ and ‘Organism 2’). I’ve gotten to this point so far:


documentclass[a4paper,10pt]{article}
usepackage[utf8x]{inputenc}
usepackage{amsmath}

begin{document}
begin{tabular}{r|c|c|}
multicolumn{1}{r}{}
 &  multicolumn{1}{c}{$S$}
 & multicolumn{1}{c}{$T$} cline{2-3}
$S$ & $a,a$ & $b,c$ cline{2-3}
$T$ & $c,b$ & $d,d$ cline{2-3}
end{tabular}

end{document}

And it currently looks like this:

column spanning table

Can anyone suggest how to add the top ‘Organism 2’ and left ‘Organism 1’ row/column entries?

thanks!

2 Answers

starting from your code, I got to this:

enter image description here

Basically, I have added the package multirow and changed the cline indexes.

documentclass[a4paper,10pt]{article}
usepackage[utf8x]{inputenc}
usepackage{amsmath}
usepackage{multirow}

begin{document}
begin{tabular}{cr|c|c|}
  multicolumn{2}{r}{} & multicolumn{2}{c}{Organism 2} 

  multicolumn{2}{r}{}
 & multicolumn{1}{c}{$S$}
 & multicolumn{1}{c}{$T$} 

  cline{3-4}


  multirow{2}{*}{Organism 1} & $S$ & $a,a$ & $b,c$ 
  cline{3-4}

 & $T$ & $c,b$ & $d,d$ 
  cline{3-4}
end{tabular}

end{document}

Correct answer by Mortimer on May 14, 2021

With {NiceTabular} of nicematrix.

documentclass{article}
usepackage{nicematrix}

begin{document}
begin{NiceTabular}{cccc}
                        &     & Block{1-2}{Organism 2} 
                        &     & $S$      & $T$ 
Block{2-1}{Organism 1} & $S$ & Block[hvlines]{2-2}{}
                                $a$, $a$ & $b$, $c$  
                        & $T$ & $c$, $b$ & $d$, $d$ 
end{NiceTabular}
end{document}

Output of the above code

Answered by F. Pantigny on May 14, 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