2

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.

3
  • Please mention the packages you are using – Ambika Vanchinathan May 6 '15 at 10:10
  • Please add the preamble, this is not a full MWE. – Alenanno May 6 '15 at 10:10
  • Sorry about that. I've added a new version which compiles on its own. – Willy G May 6 '15 at 10:16
5

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

2
  • Oh, so the macro was the problem. Thanks for this. Any idea how to make the vertical lines thicker? – Willy G May 6 '15 at 11:06
  • Use this: \begin{tabular}[ht]{|c!{\vrule width 2pt}c|c|c|c|} in the above table for a thicker vertical line for the first column – Ambika Vanchinathan May 6 '15 at 11:19

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.