# How do I avoid and entry being shifted when using \multirow and \rowcolor at the same time?

I have been looking around for and answer a while now and figured out how to make the entry in the \multirowvisible. But now the entry is being shifted for some reason. Can you please help me? Down here I have a minimal working example.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{multirow}

\usepackage{color, colortbl}

\definecolor{LightCyan}{rgb}{0.88,1,1}

\begin{document}
\begin{table}[h!]
\centering

\begin{tabular}{|l|l|l|l|l|}
\hline
Känsla & Elevgrupp & ''Gillade det ofta'' ($\%$) & ''Övriga svar'' ($\%$) &
$U$-värde ($p<0.05$) \\
\hline
\rowcolor{LightCyan}
Gillade Det & $1$ & $75$ & $25$ & \\
\rowcolor{LightCyan}
& $2$ & $37$ & $62$ & \multirow{2}{*}{$12.5$} \\
\hline
Fann det Vackert & $1$ & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& $2$ & $\cdots$ & $\cdots$ &\\
\hline
Var Imponerad & $1$ & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& $2$ & $\cdots$ & $\cdots$ &\\
\hline
Fascinerade Mig & $1$ & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& $2$ & $\cdots$ & $\cdots$ &\\
\hline

\end{tabular}
\caption{Exempel på beskrivande statistik med ett signifikanstest på elevers
svar om hur ofta de kände att gillade problemet.}
\label{tabkors3}
\end{table}
\end{document}


And this is what it looks like:

• Try with -2 instead of 2 as in \multirow{-2}{*}{$12.5$}. – leandriis Oct 6 '19 at 19:07
• Unrelated to the issue, but you might want to keep in mind that your table is a lot wider than the current textwidth. You might have to adjust the margins or introduce linebreaks to make the table fit into the textwidth. – leandriis Oct 6 '19 at 19:08
• @DG': Moving the command into the previous row works if there is no rowcolor involved. With rowcolor however, the lover half of the text will disappear: i.stack.imgur.com/aCxJW.png – leandriis Oct 6 '19 at 19:10
• @leandriis I just saw that in Heiko's answer here: tex.stackexchange.com/a/269549/29873 – DG' Oct 6 '19 at 19:15
• @leandriis You should make your comment an answer – DG' Oct 6 '19 at 19:16

If you replace 2 with -2 as in \multirow{-2}{*}{$12.5$} you will get the desired result.

With \multirow{2} you merge the cell in the current row with the cell in the following row. This is why your text overlaps with the horizontal line. Shifting the command ine row upwards is no solution since you are using rowcolor. So, instead you can use \multirow{-2} to merge the cell in the current wor with the cell in the previous row.

I'd also suggest to replace \usepackage{color,colortbl} with \usepackage[table]{xcolor}. Also, there is no need to use math mode for all the numbers. I have also removed that in the following MWE:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{multirow}

\usepackage[table]{xcolor}

\definecolor{LightCyan}{rgb}{0.88,1,1}

\begin{document}
\begin{table}[h!]
\centering

\begin{tabular}{|l|l|l|l|l|}
\hline
Känsla & Elevgrupp & ''Gillade det ofta'' ($\%$) & ''Övriga svar'' ($\%$) &
$U$-värde ($p<0.05$) \\
\hline
\rowcolor{LightCyan}
Gillade Det & 1 & 75 & 25 &\multirow{2}{*}{12.5} \\
\rowcolor{LightCyan}
& 2 & 37 & 62 &  \\
\hline
Fann det Vackert & 1 & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& 2 & $\cdots$ & $\cdots$ &\\
\hline
Var Imponerad & 1 & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& 2 & $\cdots$ & $\cdots$ &\\
\hline
Fascinerade Mig & 1 & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& 2 & $\cdots$ & $\cdots$ &\\
\hline
\end{tabular}
\caption{Exempel på beskrivande statistik med ett signifikanstest på elevers
svar om hur ofta de kände att gillade problemet.}
\label{tabkors3}
\end{table}
\end{document}


Here is a second version of the MWE that uses tabularx and makecell to make the table fit into the textwidth:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[swedish]{babel}
\usepackage{multirow}

\usepackage[table]{xcolor}
\usepackage{makecell}
\usepackage{tabularx}

\definecolor{LightCyan}{rgb}{0.88,1,1}

\begin{document}
\begin{table}[h!]
\centering

\begin{tabularx}{\textwidth}{|X|l|l|l|l|}
\hline
Känsla & Elevgrupp & \makecell{''Gillade det ofta''\\ ($\%$)} & \makecell{''Övriga svar''\\ ($\%$)} &
\makecell{$U$-värde\\ ($p<0.05$)} \\
\hline
\rowcolor{LightCyan}
& $1$ & $75$ & $25$ & \\
\rowcolor{LightCyan}
\multirow{-2}{=}{Gillade Det} & $2$ & $37$ & $62$ & \multirow{-2}{*}{$12.5$} \\
\hline
\multirow{2}{=}{Fann det Vackert} & $1$ & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& $2$ & $\cdots$ & $\cdots$ &\\
\hline
\multirow{2}{=}{Var Imponerad} & $1$ & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& $2$ & $\cdots$ & $\cdots$ &\\
\hline
\multirow{2}{=}{Fascinerade Mig} & $1$ & $\cdots$ & $\cdots$ & \multirow{2}{*}{$\cdots$} \\
& $2$ & $\cdots$ & $\cdots$ &\\
\hline
\end{tabularx}
\caption{Exempel på beskrivande statistik med ett signifikanstest på elevers
svar om hur ofta de kände att gillade problemet.}
\label{tabkors3}
\end{table}

\end{document}


I would redesign your table as follows:

Used are:

• removed vertical rules
• for horizontal rules are used rules from booktabs table; its numbers are significantly reduced
• columns with numbers are of S type (defined in siunitx package)

Edit:

• for aligning numbers in the last row is considered \tablenum macro defined in the siunitx package
\documentclass[12pt]{article}
\usepackage[swedish]{babel}

\usepackage[table]{xcolor}
\usepackage{booktabs, makecell, multirow, tabularx}
\definecolor{LightCyan}{rgb}{0.88,1,1}
\usepackage{siunitx}

\begin{document}
\begin{table}[ht!]
\centering
\sisetup{table-format=2.2}
\begin{tabularx}{\textwidth}{ X cSSc} % <---
\toprule
&   {\thead{''Gillade det ofta''\\ ($\%$)}}
&   {\thead{''Övriga svar''\\ ($\%$)}}
&   {\thead{$U$-värde\\ ($p<0.05$)}}        \\
\specialrule{\lightrulewidth}{\aboverulesep}{0pt}
\rowcolor{LightCyan}
& 1 & 75            & 25            &                                       \\
\rowcolor{LightCyan}
& 2 & 37            & 62            & \multirow{-2}{*}{\mrtf{3.2}{12.5}}    \\ % <---
\specialrule{\lightrulewidth}{0pt}{\belowrulesep}
\multirow{2}{=}{Fann det Vackert}
& 1 & {$\cdots$}    & {$\cdots$}    & \multirow{2}{*}{\mrtf{3.2}{123.45}}   \\ % <---
& 2 & {$\cdots$}    & {$\cdots$}    &                                       \\
& 1 & {$\cdots$}    & {$\cdots$}    & \multirow{2}{*}{$\cdots$} \\ % insert \mrft macro
% when \cdot is replaced by number
& 2 & {$\cdots$}    & {$\cdots$}    &                           \\    \addlinespace
& 1 & {$\cdots$}    & {$\cdots$}    & \multirow{2}{*}{$\cdots$} \\
& 2 & {$\cdots$}    & {$\cdots$}    &                           \\