我一直在尝试将下表转换为长表,因此它将扩展到多个页面,因为它对于单个页面来说太长了。
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage{makecell,multirow}
\renewcommand\theadfont{\bfseries\normalsize}
\usepackage{caption}
\usepackage{longtable}
\begin{document}
\begin{table}[htbp]
\centering
\renewcommand\arraystretch{1.5}
\caption{Add caption}
\begin{tabular}{|*{3}{c|}}
\hline
\thead{Probe Type} & \thead{Repeats Compared} & \thead{KS and p Values} \\
\hline
\multirow{6}{*}{Hydrophobic} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.56 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.008 \\
\cline{3-3} & & p = 0.58 \\
\cline{1-3}
\multirow{6}{*}{Hydrogen Bond Acceptor} & \multirow{2}{*}{1st - 2nd} & KS = 0.02 \\
\cline{3-3} & & p = 0.67 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.007 \\
\cline{3-3} & & p = 0.80 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.88 \\
\cline{1-3}
\multirow{6}{*}{Hydrogen Bond Donor} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.42 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.04 \\
\cline{3-3} & & p = 0.99 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.54 \\
\cline{1-3}
\multirow{6}{*}{Polar} & \multirow{2}{*}{1st - 2nd} & KS = 0.02 \\
\cline{3-3} & & p = 0.69 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.008 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.02 \\
\cline{3-3} & & p = 0.70 \\
\cline{1-3}
\multirow{6}{*}{Positive Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.47 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.004 \\
\cline{3-3} & & p = 0.99 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.58 \\
\cline{1-3}
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\end{tabular}
\label{tab:addlabel}
\end{table}
\end{document}
根据 stackexchange 上以前的答案并使用:
\begin{longtable}{|*{3}{c|}}
并省略了居中和标题行。但是,我仍然会出错。有什么关于如何转换的建议吗?
答案1
您需要删除table
环境并在其中插入标题longtable
:
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage{longtable,multirow,makecell}
\begin{document}
\begin{longtable}{|*{3}{c|}}
\caption{Add caption}\label{tab:addlabel}\\
\hline
\thead{Probe Type} & \thead{Repeats Compared} & \thead{KS and p Values} \\
\hline
\endfirsthead
\hline
\thead{Probe Type} & \thead{Repeats Compared} & \thead{KS and p Values} \\
\hline
\endhead
\multirow{6}{*}{Hydrophobic} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.56 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.008 \\
\cline{3-3} & & p = 0.58 \\
\hline
\multirow{6}{*}{Hydrogen Bond Acceptor} & \multirow{2}{*}{1st - 2nd} & KS = 0.02 \\
\cline{3-3} & & p = 0.67 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.007 \\
\cline{3-3} & & p = 0.80 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.88 \\
\hline
\multirow{6}{*}{Hydrogen Bond Donor} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.42 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.04 \\
\cline{3-3} & & p = 0.99 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.54 \\
\hline
\multirow{6}{*}{Polar} & \multirow{2}{*}{1st - 2nd} & KS = 0.02 \\
\cline{3-3} & & p = 0.69 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.008 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.02 \\
\cline{3-3} & & p = 0.70 \\
\hline
\multirow{6}{*}{Positive Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.47 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.004 \\
\cline{3-3} & & p = 0.99 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.58 \\
\hline
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\pagebreak
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\end{longtable}
\end{document}
由于您有\multirow
命令,因此您必须手动检查分页符并\pagebreak
在必要时插入,如示例所示
另一方面,我建议换一种认识:监禁表格太糟糕了!而且在所有行中重复 KS 或 p 也是浪费空间:您可以保存它并制作一个四列表格。
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage{longtable,booktabs,siunitx}
\begin{document}
\begin{longtable}{lcS[table-format=1.3]S[table-format=1.2]}
\caption{Add caption}\label{tab:addlabel}\\
\toprule
Probe Type & Repeats Compared & \multicolumn{2}{c@{}}{Values} \\
\cmidrule(lr){3-4}
& & {KS} & {p} \\
\midrule
\endfirsthead
\toprule
Probe Type & Repeats Compared & \multicolumn{2}{c@{}}{Values} \\
\cmidrule(l){3-4}
& & {KS} & {p} \\
\midrule
\endhead
Hydrophobic
& 1st - 2nd & 0.01 & 0.56 \\
& 1st - 3rd & 0.01 & 0.49 \\
& 2nd - 3rd & 0.008 & 0.58 \\
\midrule
Hydrogen Bond Acceptor
& 1st - 2nd & 0.02 & 0.67 \\
& 1st - 3rd & 0.007 & 0.80 \\
& 2nd - 3rd & 0.01 & 0.88 \\
\midrule
Hydrogen Bond Donor
& 1st - 2nd & 0.01 & 0.42 \\
& 1st - 3rd & 0.04 & 0.99 \\
& 2nd - 3rd & 0.01 & 0.54 \\
\midrule
Polar
& 1st - 2nd & 0.02 & 0.69 \\
& 1st - 3rd & 0.008 & 0.49 \\
& 2nd - 3rd & 0.02 & 0.70 \\
\midrule
Positive Charge
& 1st - 2nd & 0.01 & 0.47 \\
& 1st - 3rd & 0.004 & 0.99 \\
& 2nd - 3rd & 0.01 & 0.58 \\
\midrule
Negative Charge
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 1
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 2
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 3
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 4
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 5
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 6
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
\pagebreak
Negative Charge 7
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 8
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 9
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 10
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 11
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 12
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\midrule
Negative Charge 13
& 1st - 2nd & 0.08 & 0.58 \\
& 1st - 3rd & 0.08 & 0.49 \\
& 2nd - 3rd & 0.07 & 0.73 \\
\bottomrule
\end{longtable}
\end{document}
答案2
首先,您需要加载该longtable
包(并且在使用时\multirow
您也需要该包)。此外,longtable
指定标题的方式不同(除了不允许在浮动内使用外),并且makecell
表头的方法不会按预期工作。
\documentclass[a4paper,12pt,twoside]{book}
\usepackage[a4paper,width=150mm,top=25mm,bottom=25mm,bindingoffset=6mm]{geometry}
\usepackage{longtable}
\usepackage{multirow}
\begin{document}
\begingroup
\renewcommand\arraystretch{1.5}
\begin{longtable}{|*{3}{c|}}
\caption{Add caption}\label{tab:addlabel}\\
\hline
Probe Type & Repeats Compared & KS and p Values \\
\hline\endhead
\multirow{6}{*}{Hydrophobic} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.56 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.008 \\
\cline{3-3} & & p = 0.58 \\
\cline{1-3}
\multirow{6}{*}{Hydrogen Bond Acceptor} & \multirow{2}{*}{1st - 2nd} & KS = 0.02 \\
\cline{3-3} & & p = 0.67 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.007 \\
\cline{3-3} & & p = 0.80 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.88 \\
\cline{1-3}
\multirow{6}{*}{Hydrogen Bond Donor} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.42 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.04 \\
\cline{3-3} & & p = 0.99 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.54 \\
\cline{1-3}
\multirow{6}{*}{Polar} & \multirow{2}{*}{1st - 2nd} & KS = 0.02 \\
\cline{3-3} & & p = 0.69 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.008 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.02 \\
\cline{3-3} & & p = 0.70 \\
\cline{1-3}
\multirow{6}{*}{Positive Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.01 \\
\cline{3-3} & & p = 0.47 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.004 \\
\cline{3-3} & & p = 0.99 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.01 \\
\cline{3-3} & & p = 0.58 \\
\cline{1-3}
\multirow{6}{*}{Negative Charge} & \multirow{2}{*}{1st - 2nd} & KS = 0.08 \\
\cline{3-3} & & p = 0.58 \\
\cline{2-3} & \multirow{2}{*}{1st - 3rd} & KS = 0.08 \\
\cline{3-3} & & p = 0.49 \\
\cline{2-3} & \multirow{2}{*}{2nd - 3rd} & KS = 0.07 \\
\cline{3-3} & & p = 0.73 \\
\hline
\end{longtable}
\endgroup
\end{document}
答案3
\cline
这是一个解决方案,代码更简单。出于美观原因,我删除了部分s,并用\makecell
代替\multirow
。别忘了,在 longtable 中,标题是环境的一部分,位于以下\endfirsthead
部分:
\documentclass[a4paper, 12pt, twoside]{book}
\usepackage[a4paper,width=150mm, vmargin=25mm,bindingoffset=6mm]{geometry}
\usepackage{multirow, makecell, longtable}
\begin{document}
{ \setcellgapes{4pt}\makegapedcells%
\begin{longtable}{|*{3}{c|}}
\caption{Add caption}\label{tab:addlabel} \\
\hline
\thead{Probe Type} & \thead{Repeats Compared} & \thead{KS and p Values} \\
\hline
\endfirsthead
\hline
\thead{Probe Type} & \thead{Repeats Compared} & \thead{KS and p Values} \\
\hline
\endhead
\hline
\multicolumn{3}{r}{\footnotesize\itshape To be continued on next page}
\endfoot
\hline
\endlastfoot
& 1st - 2nd & \makecell{KS = 0.01 \\p = 0.56 } \\ \cline{2-3}
Hydrophobic &{1st - 3rd} & \makecell{KS = 0.01 \\ p = 0.49} \\ \cline{2-3}
& 2nd - 3rd & \makecell{KS = 0.008 \\ p = 0.58} \\
\hline
& 1st - 2nd & \makecell{KS = 0.02 \\ p = 0.67} \\ \cline{2-3}
\makecell{Hydrogen Bond\\ Acceptor} & 1st - 3rd & \makecell{KS = 0.007 \\ p = 0.80} \\ \cline{2-3}
& 2nd - 3rd & \makecell{KS = 0.01 \\ p = 0.88} \\
\hline
& 1st - 2nd & \makecell{KS = 0.01 \\ p = 0.42} \\ \cline{2-3}
\makecell{Hydrogen Bond\\ Donor} & 1st - 3rd & \makecell{KS = 0.04 \\ p = 0.99} \\ \cline{2-3}
& 2nd - 3rd & \makecell{KS = 0.01 \\ p = 0.54} \\
\hline
& 1st - 2nd & \makecell{KS = 0.02 \\ p = 0.69} \\ \cline{2-3}
Polar & 1st - 3rd & \makecell{KS = 0.008 \\ p = 0.49} \\ \cline{2-3}
& 2nd - 3rd & \makecell{KS = 0.02 \\ p = 0.70} \\
\hline
& 1st - 2nd & \makecell{KS = 0.01 \\ p = 0.47} \\ \cline{2-3}
Positive Charge & 1st - 3rd & \makecell{KS = 0.004 \\ p = 0.99} \\ \cline{2-3}
& 2nd - 3rd & \makecell{KS = 0.01 \\ p = 0.58} \\
\hline
& 1st - 2nd & \makecell{ KS = 0.08 \\ p = 0.58} \\ \cline{2-3}
Negative Charge & 1st - 3rd & \makecell{KS = 0.08 \\ p = 0.49} \\ \cline{2-3}
& 2nd - 3rd & \makecell{KS = 0.07 \\ p = 0.73}
\end{longtable}
}%
\end{document}