2

I am trying to add a vertical line in the first row between X and Y that is consistent with the placement of the vertical line in the rows below. When I do \multicolumn{3}{l|}{\textbf{X}} & \multicolumn{3}{|l}{\textbf{Y}} or \multicolumn{3}{|l|}{\textbf{X}} & \multicolumn{3}{|l|}{\textbf{Y}} the contents of the rows disappear. But these seem to be the solutions in other posts. Is there an easy fix?

\documentclass{article}
 \usepackage{array,multirow,graphicx}
  \usepackage{nicematrix}
  \usepackage{lineno}
  \usepackage{color, colortbl}
  \definecolor{aliceblue}{rgb}{0.94, 0.97, 1.0}
 \usepackage{float}
 \begin{document}

 \begin{table}[!h]
   \centering
   \begin{NiceTabular}{|c|l|l|l|l|l|l|l|}
     \hline
     & & \multicolumn{3}{l}{\textbf{X}} & \multicolumn{3}{l}{\textbf{Y}} \\ \hline
      & \textbf{Region} & \textbf{r} & \textbf{$R^2$} & \textbf{p-value}& \textbf{r} & \textbf{$R^2$} & \textbf{p-value} \\ \hline
      \Block{4-1}{\rotate{\textbf{CLCH}}}
      & Ross Sea& -0.973 & 0.947 & 2.417 e-8  & -0.996 & 0.992 & 8.704 e-13\\
      & Amundsen-Bellingshausen Seas & -0.901 & 0.813 & 7.766 e-7& -0.637 & 0.406 & 0.006  \\
      & Antarctic Peninsula  & -0.607 & 0.369 & 0.009& -0.059 & 0.004 & 0.821 \\
      & Weddell Sea& -0.590 & 0.348 & 0.013 & -0.889 & 0.789 & 1.861 e-6  \\
      & East Antarctica & -0.954 & 0.910 & 2.953 e-9 & -0.975 & 0.952 & 2.619 e-11  \\ \hline \hline
      
      \Block{5-1}{\rotate{\textbf{CLCM}}}
      \rowcolor{aliceblue}
      & Ross Sea & 0.341 & 0.117 & 0.254 & 0.842 & 0.708 & 0.0003\\
      \rowcolor{aliceblue}
      & Amundsen-Bellingshausen Seas  & 0.229 & 0.052 & 0.377 & 0.939 & 0.881 & 2.515 e-5 \\
      \rowcolor{aliceblue}
      & Antarctic Peninsula & 0.719 & 0.517 & 0.001 & -0.824 & 0.679 & 4.734 e-5 \\
      \rowcolor{aliceblue}
      & Weddell Sea & 0.817 & 0.668 & 6.204 e-5  & 0.708 & 0.501 & 0.001\\
      \rowcolor{aliceblue}
      & East Antarctica  & -0.372 & 0.138 & 0.141 & -0.414 & 0.172 & 0.098 \\ \hline
   \end{NiceTabular}
 \end{table} 

 \end{document}

example image

1

You have to add | at the end of the multicolumn specifications. The stuff between columns 'belongs' to the multicolumn preceding it.

 \multicolumn{3}{l|}{\textbf{X}} & \multicolumn{3}{l|}{\textbf{Y}}

enter image description here

\documentclass{article}
 \usepackage{array,multirow,graphicx}
  \usepackage{nicematrix}
  \usepackage{lineno}
  \usepackage{color, colortbl}
  \definecolor{aliceblue}{rgb}{0.94, 0.97, 1.0}
 \usepackage{float}
 \begin{document}

 \begin{table}[!h]
   \centering
   \begin{NiceTabular}{|c|l|l|l|l|l|l|l|}
     \hline
     & & \multicolumn{3}{l|}{\textbf{X}} & \multicolumn{3}{l|}{\textbf{Y}} \\ \hline
      & \textbf{Region} & \textbf{r} & \textbf{$R^2$} & \textbf{p-value}& \textbf{r} & \textbf{$R^2$} & \textbf{p-value} \\ \hline
      \Block{4-1}{\rotate{\textbf{CLCH}}}
      & Ross Sea& -0.973 & 0.947 & 2.417 e-8  & -0.996 & 0.992 & 8.704 e-13\\
      & Amundsen-Bellingshausen Seas & -0.901 & 0.813 & 7.766 e-7& -0.637 & 0.406 & 0.006  \\
      & Antarctic Peninsula  & -0.607 & 0.369 & 0.009& -0.059 & 0.004 & 0.821 \\
      & Weddell Sea& -0.590 & 0.348 & 0.013 & -0.889 & 0.789 & 1.861 e-6  \\
      & East Antarctica & -0.954 & 0.910 & 2.953 e-9 & -0.975 & 0.952 & 2.619 e-11  \\ \hline \hline
      \rowcolor{aliceblue}
      \Block{5-1}{\rotate{\textbf{CLCM}}}
      & Ross Sea & 0.341 & 0.117 & 0.254 & 0.842 & 0.708 & 0.0003\\
      \rowcolor{aliceblue}
      & Amundsen-Bellingshausen Seas  & 0.229 & 0.052 & 0.377 & 0.939 & 0.881 & 2.515 e-5 \\
      \rowcolor{aliceblue}
      & Antarctic Peninsula & 0.719 & 0.517 & 0.001 & -0.824 & 0.679 & 4.734 e-5 \\
      \rowcolor{aliceblue}
      & Weddell Sea & 0.817 & 0.668 & 6.204 e-5  & 0.708 & 0.501 & 0.001\\
      \rowcolor{aliceblue}
      & East Antarctica  & -0.372 & 0.138 & 0.141 & -0.414 & 0.172 & 0.098 \\ \hline
   \end{NiceTabular}
 \end{table} 

 \end{document}
3
  • Hello, thanks for the help. When I run it with the corrected line in Tex studio I get the desire result no problem but when I run that same code with the corrected line in Overleaf (my document is in Overleaf so ideally I need it to work in Overleaf) I get the following error : 'Package array Error: <{..} at wrong position: changed to !{..}.' for the line that you corrected ... and my output looks the same as the image I posted above. Is this an issue with Overleaf? Any thoughts?
    – madschm
    Aug 2 at 18:25
  • @madschm Overleaf uses an old LaTeX installation. Apparently the 2020 version of nicematrix had an issue that was removed in the 2021 verison that I'm using locally. Locate the file nicematrix.sty on your computer (with texlive, you can try kpsewhich nicematrix.sty) and copy it to overleaf.
    – gernot
    Aug 2 at 18:45
  • Thank you, that worked perfectly. For anyone viewing this answer later I saved the following file and uploaded it to my overleaf document: tug.org/svn/texlive/trunk/Master/texmf-dist/tex/latex/…
    – madschm
    Aug 2 at 19:04
1

An alternative solution with tabularray pacakge. If you want to use it in Overleaf, you need to download tabularray.sty and ninecolors.sty first:

https://ctan.org/tex-archive/macros/latex/contrib/tabularray https://ctan.org/tex-archive/macros/latex/contrib/ninecolors

PS: you could use siunitx package to align numberic values.

\documentclass{article}

\usepackage{graphicx}
\usepackage{xcolor}
\definecolor{aliceblue}{rgb}{0.94,0.97,1.0}
\usepackage{float}
\usepackage{tabularray}

\begin{document}

\begin{table}[!h]
   \centering
   \begin{tblr}{
     colspec = {|c|l|r|l|l|r|l|l|l|},
     row{1,2} = {font=\bfseries}, column{1} = {font=\bfseries},
     cell{1}{3,6} = {c=3}{l}, row{8-12} = {aliceblue},
     cell{3}{1} = {r=4}{c}, cell{8}{1} = {r=5}{c},
   }
     \hline
      &                              & X      &       &         & Y & & \\
     \hline
      & Region                       & r      & $R^2$ & p-value & r & $R^2$ & p-value \\
     \hline
      \rotatebox{90}{CLCH}
      & Ross Sea                     & -0.973 & 0.947 & 2.417 e-8  & -0.996 & 0.992 & 8.704 e-13 \\
      & Amundsen-Bellingshausen Seas & -0.901 & 0.813 & 7.766 e-7& -0.637 & 0.406 & 0.006  \\
      & Antarctic Peninsula          & -0.607 & 0.369 & 0.009& -0.059 & 0.004 & 0.821 \\
      & Weddell Sea                  & -0.590 & 0.348 & 0.013 & -0.889 & 0.789 & 1.861 e-6  \\
      & East Antarctica              & -0.954 & 0.910 & 2.953 e-9 & -0.975 & 0.952 & 2.619 e-11  \\
     \hline \hline
      \rotatebox{90}{CLCM}
      & Ross Sea                     & 0.341 & 0.117 & 0.254 & 0.842 & 0.708 & 0.0003 \\
      & Amundsen-Bellingshausen Seas & 0.229 & 0.052 & 0.377 & 0.939 & 0.881 & 2.515 e-5 \\
      & Antarctic Peninsula          & 0.719 & 0.517 & 0.001 & -0.824 & 0.679 & 4.734 e-5 \\
      & Weddell Sea                  & 0.817 & 0.668 & 6.204 e-5  & 0.708 & 0.501 & 0.001 \\
      & East Antarctica              & -0.372 & 0.138 & 0.141 & -0.414 & 0.172 & 0.098 \\
     \hline
   \end{tblr}
 \end{table}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.