latextabularmultirow

How to remove vertical lines when combining multirow and multicolumn in a tabular?


I had a look at a few similar questions but none seems to be identical to mine.

Here is a MWE:

\documentclass[a4paper]{article}

\usepackage{multirow}
\usepackage{multicol}

\begin{document}

\begin{tabular}{|*{5}{c|}}
\hline 
\backslashbox{1}{2} & A & B & C & D \\
\hline 
a & \multicolumn{3}{c|}{\multirow{3}{*}{P}}   & x \\
\cline{1-1} \cline{5-5}
b  & & & & y  \\
\cline{1-1} \cline{5-5}
c & & &  & z \\
\hline 
d & q & n & t & r \\
\hline 
e & l & m & s & p \\
\hline 
\end{tabular}

\end{document}

The column B is partially bounded by 2 vertical lines. I would prefer to have a big 3 by 3 cell for the entry P.

How can I do that?


Solution

  • Just add "phantom" multicolumns below the cell containing P:

    \documentclass[a4paper]{article}
    
    \usepackage{multirow}
    \usepackage{multicol}
    \begin{document}
    
    \begin{tabular}{|*{5}{c|}}
    \hline 
    \backslashbox{1}{2}  & A & B & C & D \\
    \hline 
    a & \multicolumn{3}{c|}{\multirow{3}{*}{P}}   & x \\
    \cline{1-1} \cline{5-5}
    %% Add a \multicolumn here
    b  & \multicolumn{3}{c|}{}   & x \\
    \cline{1-1} \cline{5-5}
    %% Add a \multicolumn here
    c & \multicolumn{3}{c|}{}& z \\
    \hline 
    d & q & n & t & r \\
    \hline 
    e & l & m & s & p \\
    \hline 
    \end{tabular}
    
    \end{document}