表格环境中的空行

表格环境中的空行

我有一个问题。我正在表格环境中制作一个表格;它有多行、多列、单元格颜色以及所有常见的服饰用品。

但是,表格中缺少一些线(例如在特定单元格的边缘),我似乎无法修复它们。

这是我的 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}

正如您所看到的,表格最左侧的线条有一些小的断点,并且右下角没有显示边框!

有人能帮助我吗?

谢谢,

大号

答案1

您省略了第 31 行中的管道符号,该符号|c|必须出现,以便消除表格右下角未链接的错误。第 28、29、30 行必须包含\hhline{|~|-|-|-|-|-|}在最后

正确的代码

\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}

答案2

正确使用 后,左侧垂直线中的小断点会消失\hhline。缺失垂直线的问题已得到解决,正如@Christian Hupfer 所说。我还简化了您的代码:color如果您加载xcolor,则加载是无用的,我不明白您为什么要用 包装您multirow\parbox

我添加了另一种方法来改善你的表格:

\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} 

在此处输入图片描述

答案3

{NiceTabular}使用创建该表很容易nicematrix

\documentclass[12pt,letterpaper,twoside,openright]{book}
\usepackage[margin=1.0in]{geometry}
\usepackage[font=footnotesize,labelfont=bf]{caption}

\usepackage{nicematrix}
\usepackage{enumitem} % required to use \tabularnote in {NiceTabular}

\begin{document}

\begin{table}
\centering
\captionsetup{font=large}
\caption{caption}
\renewcommand{\arraystretch}{1.4}
\begin{NiceTabular}{cccccc}[color-inside,hvlines]
\Block{*-1}{\rotate Response 2}
& Not tested & 0 & 0 & 0 & 2 \\ 
& Nil & 1 & 1 & 0 & 0 \\ 
& Inhibited & \cellcolor{green!25}6 & \cellcolor{blue!25}7\tabularnote[$\dagger$]{\color{red}footnote 1}& 2 & 1 \\ 
& Excited & \cellcolor{red!25}20\tabularnote[*]{\color{blue}footnote 2} & \cellcolor{yellow!25}3 & 0 & 0 \\ 
& Total & Excited & Inhibited & Nil & Not tested \\ 
& \Block{1-5}{Response 1} \\ 
\end{NiceTabular}
\end{table}

\end{document}

您需要进行多次编译(因为nicematrix在后台使用了 PGF/TikZ 节点)。

上述代码的输出

相关内容