[Tex/LaTex] Multirow and Multicolumn with missing lines

multicolmultirowtables

I am trying to create a table which uses both multicolumns and multirows, and I am getting some graphical problems.

As you can see on below image, the top right corner is missing a line and the second horizontal line cuts off in the middle of a cell)

Table Image

Find the code below.

\documentclass{article}

%Used to create Macro 1
\usepackage{array}

\usepackage{multirow}

%Used for \textsubscript
\usepackage{fixltx2e}

%Macro
\newcolumntype{"}{@{\hskip\tabcolsep\vrule width 1pt\hskip\tabcolsep}}
\makeatother

\begin{document}


\begin{table}
       \centering
       \begin{tabular}[ht]{|c"c|c|c|c|}

              \hline

              \multirow{2}{*}{\textbf{Change}}          & \multicolumn{2}{c}{\textbf{Main}}       & \multicolumn{2}{c}{\textbf{Sub}}        \\ \cline{2-5}

                     & \textbf{P}                & \textbf{A}                & \textbf{P}                & \textbf{A}         \\ \hline    
              1      & U                         & R\textsubscript{ef}       & R\textsubscript{ef}       & U                  \\ \hline
              2      & U                         & U                         & R\textsubscript{ef}       & R\textsubscript{ef} \\ \hline
              3      & G                         & P                         & P                         & G                  \\ \hline
              4      & P                         & P                         & G                         & G                  \\ \hline
              5      & A                         & A                         & N/A                       & N/A                \\ \hline
              6      & E                         & E                         & N/A                       & N/A                \\ \hline
              7      & E                         & E                         & N/A                       & N/A                \\ \hline
              8      & E                         & E                         & N/A                       & N/A                \\ \hline
              9      & E                         & E                         & N/A                       & N/A                \\ \hline
              10     & E                         & E                         & G                         & G                  \\ \hline
              11     & E                         & E                         & G                         & G                  \\ \hline
              12     & E                         & E                         & G                         & G                  \\ \hline
              13     & R\textsubscript{ed}       & R\textsubscript{ed} &     N/A                         & N/A                \\ \hline


       \end{tabular}
       \caption{X }
       \label{table:X}
\end{table}


\end{document}

If you need any additional information, please leave a comment and I'll add info.

Best Answer

Check this:

Added | in the tabular specification as

\begin{tabular}[ht]{|c|c|c|c|c|} %%instead of "

and

 \multicolumn{2}{c|}{\textbf{Sub}}  %%note the | after c

giving

\documentclass{article}

%Used to create Macro 1
\usepackage{array}

\usepackage{multirow}

 %Used for \textsubscript
 \usepackage{fixltx2e}

 %Macro

\newcolumntype{"}{@{\hskip\tabcolsep\vrule width 1pt\hskip\tabcolsep}}
\makeatother

\begin{document}


\begin{table}
   \centering
   \begin{tabular}[ht]{|c|c|c|c|c|} %%added | here instead of "

          \hline

          \multirow{2}{*}{\textbf{Change}}          & \multicolumn{2}{c}{\textbf{Main}}       & \multicolumn{2}{c|}{\textbf{Sub}}        \\ %added | after c       \cline{2-5}

                 & \textbf{P}                & \textbf{A}                & \textbf{P}                & \textbf{A}         \\ \hline    
          1      & U                         & R\textsubscript{ef}       & R\textsubscript{ef}       & U                  \\ \hline
          2      & U                         & U                         & R\textsubscript{ef}       & R\textsubscript{ef} \\ \hline
          3      & G                         & P                         & P                         & G                  \\ \hline
          4      & P                         & P                         & G                         & G                  \\ \hline
          5      & A                         & A                         & N/A                       & N/A                \\ \hline
          6      & E                         & E                         & N/A                       & N/A                \\ \hline
          7      & E                         & E                         & N/A                       & N/A                \\ \hline
          8      & E                         & E                         & N/A                       & N/A                \\ \hline
          9      & E                         & E                         & N/A                       & N/A                \\ \hline
          10     & E                         & E                         & G                         & G                  \\ \hline
          11     & E                         & E                         & G                         & G                  \\ \hline
          12     & E                         & E                         & G                         & G                  \\ \hline
          13     & R\textsubscript{ed}       & R\textsubscript{ed} &     N/A                         & N/A                \\ \hline


   \end{tabular}
   \caption{X }
   \label{table:X}
\end{table}


\end{document}

enter image description here

For a thicker vertical line use

\begin{tabular}[ht]{|c!{\vrule width 2pt}c|c|c|c|}

for an output like this:

enter image description here