Blank lines in tabular environment

3,290

Solution 1

You have omitted to give pipe symbol in line no. 31 where |c| must appear so as to remove the error of unlinked bottom right corner of the table. Line no.28,29,30 must contain \hhline{|~|-|-|-|-|-|} in the last

Correct code

\documentclass[12pt,letterpaper,twoside,openright]{book}
\usepackage[margin=1.0in]{geometry}

\usepackage{multirow}
\usepackage{booktabs}

\usepackage{hhline}

\usepackage[table]{xcolor}
\usepackage{rotating}
\usepackage[para]{threeparttable}

\usepackage[font=footnotesize,labelfont=bf]{caption}
\usepackage{color, colortbl}

\begin{document}

\begin{table}
\centering
\captionsetup{font=large}
\caption{caption}
\begin{threeparttable}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\parbox[t]{2mm}{\multirow{6}{*}{\rotatebox[origin=|c]{90}{Response 2}}}
& Not tested & 0 & 0 & 0 & 2 \\ \hhline{~-|-|-|-|-|}
& Nil & 1 & 1 & 0 & 0 \\ \hhline{~-|-|-|-|-|}
& Inhibited & \cellcolor{green!25}6 & \cellcolor{blue!25}7$^{\dagger}$ & 2 & 1 \\ \hhline{|~|-|-|-|-|-|}
& Excited & \cellcolor{red!25}20$^\ast$ & \cellcolor{yellow!25}3 & 0 & 0 \\ \hhline{|~|-|-|-|-|-|}
& Total & Excited & Inhibited & Nil & Not tested \\ \hhline{|~|-|-|-|-|-|}
& \multicolumn{5}{|c|}{Response 1} \\ \hhline{-|-|-|-|-|-|}
\end{tabular}
\begin{tablenotes}
\footnotesize
   \item[$\ast$] \textcolor{red}{footnote 1} \\
   \item[$\dagger$] \textcolor{blue}{footnote 2}
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document}

Solution 2

The little breaks in the left-hand vertical line disappears with a coorect use of \hhline. The missing vertical line problem is solved as said @Christian Hupfer. I also simplified a little your code: it's useless to load color if you load xcolor, and I don't see why you wrap your multirow in a \parbox.

I added another way to improve your table:

\documentclass[12pt,letterpaper,twoside,openright]{book}
\usepackage[margin=1.0in]{geometry}
\usepackage{hhline}

\usepackage{multirow}
\usepackage{booktabs}

\usepackage[table]{xcolor}
\usepackage{colortbl}
\usepackage{rotating}
\usepackage[para]{threeparttable}

\usepackage[font=footnotesize,labelfont=bf]{caption}

\newcommand\colhead[1]{\multicolumn{1}{c}{#1}}

\usepackage{cellspace}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}

\raggedbottom

\begin{document}

\begin{table}[!h]
\centering
\captionsetup{font=large}
\caption{caption}
\begin{threeparttable}
\begin{tabular}{|c|c|c|c|c|c|}
\hline
\multirow{6}{*}{\rotatebox[origin=c]{90}{Response 2}}%
& Not tested & 0 & 0 & 0 & 2 \\
\hhline{|~|-|-|-|-|-|}
& Nil & 1 & 1 & 0 & 0 \\
\hhline{|~|-|-|-|-|-|}
& Inhibited & \cellcolor{green!25}6 & \cellcolor{blue!25}7$^{\dagger}$ & 2 & 1 \\
\hhline{|~|-|-|-|-|-|}
& Excited & \cellcolor{red!25}20$^\ast$ & \cellcolor{yellow!25}3 & 0 & 0 \\
\hhline{|~|-|-|-|-|-|}
& \textbf{Total} & Excited & Inhibited & Nil & Not tested \\
\hhline{|~|-|-|-|-|-|}
& \multicolumn{5}{c|}{Response 1} \\
\hhline{|-|-|-|-|-|-|}
\end{tabular}
\begin{tablenotes}
\footnotesize
   \item[$\ast$] \textcolor{red}{footnote 1} \\
   \item[$\dagger$] \textcolor{blue}{footnote 2}
\end{tablenotes}
\end{threeparttable}
\end{table}

\begin{table}[!h]
\centering
\captionsetup{font=large, singlelinecheck = false, justification = raggedleft}
\begin{threeparttable}
\caption{caption}
\begin{tabular}{rSr|*{4}{c|}}
\cline{3-6}
\multirow{6}{*}{\rotatebox[origin=c]{90}{Response 2}}%
& Not tested & 0 & 0 & 0 & 2 \\
\hhline{~~|-|-|-|-|}
& Nil & 1 & 1 & 0 & 0 \\
\hhline{~~|-|-|-|-|}
& Inhibited & \cellcolor{green!25}6 & \cellcolor{blue!25}7$^{\dagger}$ & 2 & 1 \\
\hhline{~~-|-|-|-|}
& Excited & \cellcolor{red!25}20$^\ast$ & \cellcolor{yellow!25}3 & 0 & 0 \\
\hhline{~~|-|-|-|-|}
\addlinespace[3pt]
& \colhead{\bfseries Total} & \colhead{Excited} &\colhead{ Inhibited} & \colhead{Nil }& \colhead{Not tested} \\
\addlinespace
\multicolumn{2}{c}{} & \multicolumn{4}{c}{Response 1}
\end{tabular}
\begin{tablenotes}
\footnotesize
   \item[$\ast$] \textcolor{red}{footnote 1} \\
   \item[$\dagger$] \textcolor{blue}{footnote 2}
\end{tablenotes}
\end{threeparttable}
\end{table}

\end{document} 

enter image description here

Share:
3,290

Related videos on Youtube

Admin
Author by

Admin

Updated on August 01, 2022

Comments

  • Admin
    Admin over 1 year

    I have a problem. I am making a table in the tabular environment; it has multirows and multicolumns and cell colours and all the usual haberdashery.

    However, there are lines missing in the table (e.g. at the edges of particular cells) and I can't seem to fix them.

    Here is my MWE:

    \documentclass[12pt,letterpaper,twoside,openright]{book}
    \usepackage[margin=1.0in]{geometry}
    
    \usepackage{multirow}
    \usepackage{booktabs}
    
    \usepackage{hhline}
    
    \usepackage[table]{xcolor}
    \usepackage{rotating}
    \usepackage[para]{threeparttable}
    
    \usepackage[font=footnotesize,labelfont=bf]{caption}
    \usepackage{color, colortbl}
    
    \begin{document}
    
    \begin{table}
    \centering
    \captionsetup{font=large}
    \caption{caption}
    \begin{threeparttable}
    \begin{tabular}{|c|c|c|c|c|c|}
    \hline
    \parbox[t]{2mm}{\multirow{6}{*}{\rotatebox[origin=c]{90}{Response 2}}}
    & Not tested & 0 & 0 & 0 & 2 \\ \hhline{~|-|-|-|-|-|}
    & Nil & 1 & 1 & 0 & 0 \\ \hhline{~|-|-|-|-|-|}
    & Inhibited & \cellcolor{green!25}6 & \cellcolor{blue!25}7$^{\dagger}$ & 2 & 1 \\ \hhline{~|-|-|-|-|-|}
    & Excited & \cellcolor{red!25}20$^\ast$ & \cellcolor{yellow!25}3 & 0 & 0 \\ \hhline{~|-|-|-|-|-|}
    & Total & Excited & Inhibited & Nil & Not tested \\ \hhline{~|-|-|-|-|-|}
    & \multicolumn{5}{c}{Response 1} \\ \hhline{|-|-|-|-|-|-|}
    \end{tabular}
    \begin{tablenotes}
    \footnotesize
       \item[$\ast$] \textcolor{red}{footnote 1} \\
       \item[$\dagger$] \textcolor{blue}{footnote 2}
    \end{tablenotes}
    \end{threeparttable}
    \end{table}
    
    \end{document}
    

    As you can see the far left hand line on the table has little breaks in it, and the bottom right hand corner is not showing a border!!

    Can someone help me please?

    Thanks,

    L

    • Admin
      Admin about 9 years
      Welcome to TeX.SX! Your table will be punished by the holy table inquisition for too much lines ;-)
    • Admin
      Admin about 9 years
      The missing edges on the coloured cells are a pdf viewer issue -- zoom in and you will see them (in printing they appear)...\multicolumn{5}{c|}{Response 1} will provide the missing vertical line ;-) But again, there are too much (vertical) lines inside the table.
  • SigmaPiEpsilon
    SigmaPiEpsilon about 9 years
    \multicolumn{5}{|c|} adds a most probably unwanted doubled vertical line at the beginning of the 2nd column then
  • murugan
    murugan about 9 years
    pipe in front of |c| could be removed. \multicolumn{5}{c|} will solve your problem. The vertical line at the beginning of the second column is covered already.