Multirows overlapping and extending past page

multirowtables

I have been trying for a few days now to fix this table in my Overleaf file. The multirows are extending past the page, and some of the cells are overlapping. There also seems to be a break in a \cline.

\documentclass[acmsmall, anonymous=true]{acmart}

\usepackage{multirow}
\usepackage{graphicx}
\usepackage{tabularx}

\newcolumntype{Y}{>{\centering\arraybackslash}X}
\newcolumntype{d}{>{\centering}b{.03\textwidth}}

\begin{table}[hbt!]
\centering
\def\tabularxcolumn#1{m{#1}}
\begin{tabularx}{\textwidth}{cdYX}
\textit{Phase} &  & \multicolumn{1}{c}{\textit{Step}} & \multicolumn{1}{c}{\textit{Difficulties a Potential Data Subject Faces with Each Step}} \\
\multicolumn{1}{c|}{\multirow{8}{*}{\textbf{Collection}}} &  & \multirow{2}{=}{Data Source} & \multirow{2}{*}{looooooong looooooong looooooong looooooong cell looooooong looooooong looooooong looooooong cell}
\\ \cline{2-2}
\multicolumn{1}{c|}{} &  &  &  \\
\multicolumn{1}{c|}{} &  & \multirow{2}{*}{Subject Type} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{c|}{} &  &  &  \\
\multicolumn{1}{c|}{} &  & \multirow{2}{*}{Awareness and Consent} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{c|}{} &  &  &  \\
\multicolumn{1}{c|}{} &  & \multirow{2}{*}{Original Data Licensing} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{c|}{} &  &  &  \\ \hline
\multicolumn{1}{l|}{\textbf{Packaging}} &  & \multirow{2}{*}{Dataset Availability} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{l|}{} &  &  &  \\
\multicolumn{1}{l|}{} &  & \multirow{2}{*}{Dataset Licensing} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{l|}{} &  &  &  \\
\multicolumn{1}{l|}{} &  & \multirow{2}{*}{Prohibited Uses} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{l|}{} &  &  &  \\ \cline{1-1} \cline{3-4} 
\multicolumn{1}{l|}{\textbf{Use}} &  & \multirow{2}{*}{Model Use} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{l|}{} &  &  &  \\
\multicolumn{1}{l|}{} &  & \multirow{2}{*}{Dataset Derivatives} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{l|}{} &  &  &  \\
\multicolumn{1}{l|}{} &  & \multirow{2}{*}{Derivative Domain Shift} & \multirow{2}{*}{x} \\ \cline{2-2}
\multicolumn{1}{l|}{} &  &  &  \\ \cline{1-3}
\multicolumn{1}{l|}{\textbf{Retraction}} &  &  & \multirow{2}{*}{x} \\ \cline{2-3}
\multicolumn{1}{l|}{} &  &  & 
\end{tabularx}
 \caption[x]{\small x}
    \label{table:source}    
    \vspace{-5mm}
\end{table}
\FloatBarrier

enter image description here

When I have tried some solutions I've found on other posts, like specifying the cell width, I instead get this:

enter image description here

A sketch of the desired output (apologize it is crappy, I just moved things around in paint):

enter image description here

Any help would be much appreciated.

Best Answer

I also made a solution with the tabularray package, which makes it much easier. This is a rather new package, so it may be a bit scary to use it. But it makes it much easier, as it automatically takes the actual size of cells into account. So it works also correctly with much larger texts, without you having to adjust numbers in \multirow.

I defined a rule (\RR) for the second column which I use instead of the \cline{2-2}. This is more robust. I also vertically centered the labels in the first column.

\documentclass[acmsmall, anonymous=true]{acmart}

\usepackage{tabularray}

\newcommand{\RR}{\rule[0.5ex]{6mm}{0.4pt}} % rule for second column

\begin{document}
\begin{table}[hbt!]
  \centering
  \begin{tblr}{ l | Q[l,m,colsep=0pt] X[1,l,m] X[3,l,m] }
    \textit{Phase} & & \SetCell[c=1]{c}{\textit{Step}} &
    \SetCell[c=1]{c}{\textit{Difficulties a Potential Data Subject
        Faces with Each Step}} \\ \hline
    \SetCell[r=4]{m}\textbf{Collection}
      & \RR & Data Source & 
          looooooong looooooong looooooong looooooong cell looooooong looooooong looooooong looooooong cell \\ 
      & \RR & Subject Type & x \\
      & \RR & Awareness and Consent & x \\
      & \RR & Original Data Licensing & x \\ \hline
      \SetCell[r=3]{m}\textbf{Packaging} & \RR &Dataset Availability & x \\ 
      & \RR & Dataset Licensing & x \\
      & \RR & Prohibited Uses & x \\
      \cline{1-1} \cline{3-4}
      \SetCell[r=3]{m}\textbf{Use} & \RR & Model Use & x \\
      & \RR & Dataset Derivatives & x \\
      & \RR & Derivative Domain Shift & x \\
      \cline{1-3}
      \textbf{Retraction} & & & x  \\ \cline{2-3} 
   \end{tblr}
  \caption[x]{\small x}
  \label{table:source}
  \vspace{-5mm}
\end{table}
%\FloatBarrier
\end{document}

enter image description here

Related Question