我有这个代码:
\documentclass[12pt]{report}% Not sure what this is for
\usepackage{array,ltablex,makecell}% ltablex loads tabularx and longtable also
\renewcommand\theadfont{\normalsize\bfseries}
% \renewcommand*\descriptionlabel[1]{\hspace\leftmargin$#1$}%This is for descriptions to appear on the LHS with an indent
\newenvironment{conditions}
{\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} @{${}={}$} l}}
{\end{tabular}\par\vspace{\belowdisplayskip}}%This is for descriptions of equations
\usepackage[]{multirow}%Essential for cells in table spanning multiple rows
\usepackage[autostyle]{csquotes}% This is for quotes
% \usepackage{tabulary}% This is for tables
\usepackage{ragged2e}% This is formatting for long tables
\usepackage[font={small}]{caption}
\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{U}{>{\raggedright\arraybackslash\hspace{0pt}}X}%This is a wrapper to make everything a certain width -left aligned columns with stuff at the top.
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}%C is for central aligned columns and middle aligned, p puts stuff at the bottom, m middles everything.
\newcolumntype{Y}{>{\centering\arraybackslash\hspace{0pt}}X}%C is for central aligned columns and middle aligned.
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
% \newcommand{\specialcell}[2][c]{\begin{tabular}[#1]{@{}c@{}}#2\end{tabular}}%This is to force new lines in cells
\usepackage{graphicx}% This is for images
\usepackage{booktabs,dcolumn,caption}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}%This is for precision tables per property
% \captionsetup{labelsep=newline,singlelinecheck=false} % optional, this makes the caption numbers appear on a new line.
\newcolumntype{d}[1]{D{.}{.}{#1}} % "decimal" column type
\begin{document}
\begin{table}[!ht]
\begin{small}
\centering
\ra{1.0}
\begin{tabular}{m{2cm}m{4cm}|c|c|c||c|c|c|}
\cline{3-8}
& & \multicolumn{3}{ c|| }{Test Set 1} & \multicolumn{3}{ c| }{Test Set 2} \\\cline{3-8}
& & Precision & Recall & F1 & Precision & Recall & F1 \\ \hline
\multicolumn{1}{ |m{2cm}}
{\multirow{8}{2cm}{Distantly Supervised Models} }
&
\multicolumn{1}{ |m{4cm}| }{No APE Threshold w/o Probability Threshold} &
3 & 2 & 0 & 1 & 2 & 3 \\ \cline{2-8}
&
\multicolumn{1}{ |m{4cm}| }{No APE Threshold w/ Probability Threshold} &
2 & 3 & 1 & 0 & 2 & 3 \\ \cline{2-8}
&
\multicolumn{1}{ |m{4cm}| }{APE Threshold w/o Probability Threshold} &
2 & 3 & 1 & 0 & 2 & 3 \\ \cline{2-8}
&
\multicolumn{1}{ |m{4cm}| }{APE Threshold w/ Probability Threshold} &
2 & 3 & 1 & 0 & 2 & 3 \\ \cline{1-8}
\end{tabular}
\end{small}
\end{table}
\end{document}
改编自此处:
https://en.wikibooks.org/wiki/LaTeX/Tables
其结果是:
为什么第一列没有通向左边的一条完整的垂直线?
答案1
我不会提供这样的表格,原因我相信在回答你之前的问题时已经解释过了。但是,如果你必须这样做,那么你想要的是这样的表格,其中
{|m{2cm}|m{4cm}|c|c|c||c|c|c|}
给出列的默认规范。请注意,这样,您只需要 2 个例外来调整前两行的垂直规则。(您可以使用一个 - 两个似乎更容易。)
\documentclass[12pt]{report}
\usepackage{array}
\usepackage[]{multirow}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\begin{document}
\begin{table}[!ht]
\small
\centering
\ra{1.0}
\begin{tabular}{|m{2cm}|m{4cm}|c|c|c||c|c|c|}
\cline{3-8}
\multicolumn{2}{c|}{} & \multicolumn{3}{ c|| }{Test Set 1} & \multicolumn{3}{ c| }{Test Set 2} \\\cline{3-8}
\multicolumn{2}{c|}{} & Precision & Recall & F1 & Precision & Recall & F1 \\ \hline
\multirow{8}{2cm}{Distantly Supervised Models}
&
No APE Threshold w/o Probability Threshold &
3 & 2 & 0 & 1 & 2 & 3 \\ \cline{2-8}
&
No APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ \cline{2-8}
&
APE Threshold w/o Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ \cline{2-8}
&
APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ \cline{1-8}
\end{tabular}
\end{table}
\end{document}
编辑
Bernard 的建议是使用hhline
来让表格变得稍微小一点...好吧,让它变得好一点。我在这里只用过这个作为例子,而且由于我不会用这种方式展示我自己的表格,所以我不知道这是否是最有效的使用方法。
但这是一个例子。
\documentclass[12pt]{report}
\usepackage{array,hhline}
\usepackage[]{multirow}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\begin{document}
\begin{table}[!ht]
\small
\centering
\ra{1.0}
\begin{tabular}{||m{2cm}|m{4cm}||c|c|c||c|c|c||}
\hhline{~~|t:*{3}{=}:t:*{3}{=}:t|}
\multicolumn{2}{c||}{} & \multicolumn{3}{ c|| }{Test Set 1} & \multicolumn{3}{ c|| }{Test Set 2} \\\hhline{~~||---||---||}
\multicolumn{2}{c||}{} & Precision & Recall & F1 & Precision & Recall & F1 \\ \hhline{|t:==:|-|-|-||-|-|-||}
\multirow{8}{2cm}{Distantly Supervised Models}
&
No APE Threshold w/o Probability Threshold &
3 & 2 & 0 & 1 & 2 & 3 \\ \hhline{||~-||---||---||}
&
No APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ \hhline{||~-||---||---||}
&
APE Threshold w/o Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ \hhline{||~-||---||---||}
&
APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ \hhline{|b:==:b:*{3}{=}:b:*{3}{=}:b|}
\end{tabular}
\end{table}
\end{document}
答案2
这里列出了另外三种使用变体hhline
,当然还有许多其他包:
\documentclass[12pt]{report}
\usepackage{geometry} \usepackage{array}
\usepackage[]{multirow, graphicx, hhline, rotating, makecell, cellspace}
\setlength{\cellspacetoplimit}{4pt}
\setlength{\cellspacebottomlimit}{4pt}
\newcommand{\ra}[1]{\renewcommand{\arraystretch}{#1}}
\begin{document}
\begin{table}[!ht]
\small
\centering\setlength\doublerulesep{5pt}
\ra{1.0}
\begin{tabular}{c|S{m{4cm}}||c|c|c||c|c|c|
}
\multicolumn{2}{c}{} & \multicolumn{3}{ c }{\sffamily Test Set 1} & \multicolumn{3}{ c}{\sffamily Test Set 2} \\%
\hhline{~~|---||---}
\multicolumn{2}{c|}{} & Precision & Recall & F1 & Precision & Recall & F1 \\
\hhline{~|-||---||---}
\multirowcell{8}[10pt]{\rotatebox[origin = c]{90}{\sffamily Distantly Supervised Models}}
&
No APE Threshold w/o Probability Threshold &
3 & 2 & 0 & 1 & 2 & 3 \\ %
\hhline{~|-||---||---}
&
No APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ %
\hhline{~|-||---||---} & APE Threshold w/o Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\
\hhline{~-||---||---}
&
APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\
\hhline{~-||---||---}
\end{tabular}
\end{table}
\begin{table}[!htb]
\small\
\centering\setlength\doublerulesep{5pt}
\ra{1.0}\setlength\extrarowheight{3pt}
\begin{tabular}{|m{4cm}||c|c|c||c|c|c|}
\multicolumn{1}{c}{\sffamily \multirowcell{2}{Distantly Supervised \\Models}} & \multicolumn{3}{c}{\sffamily Test Set 1} & \multicolumn{3}{c}{\sffamily Test Set 2} \\%
\hhline{|~||---||---}
\multicolumn{1}{c|}{}& Precision & Recall & F1 & Precision & Recall & F1 \\
\hhline{-||---||---}%
No APE Threshold w/o Probability Threshold &
3 & 2 & 0 & 1 & 2 & 3 \\ %
\hhline{-||---||---}
No APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ %
\hhline{-||---||---}
APE Threshold w/o Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\
\hhline{-||---||---}
APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\
\hhline{-||---||---}
\end{tabular}
\end{table}
\begin{table}[!ht]
\small
\centering\setlength\doublerulesep{5pt}
\ra{1.0}
\begin{tabular}{c|S{m{4cm}}||c|c|c||c|c|c|}
\multicolumn{2}{c}{} & \multicolumn{3}{ c }{\sffamily Test Set 1} & \multicolumn{3}{ c}{\sffamily Test Set 2} \\%
\hhline{~~|---||---}
\multicolumn{1}{c}{}& \multicolumn{1}{@{}l|}{\sffamily Models} & Precision & Recall & F1 & Precision & Recall & F1 \\
\hhline{~|-||---||---}
\multirowcell{6}[10pt]{\rotatebox[origin = c]{90}{\sffamily Distantly Supervised}}
&
No APE Threshold w/o Probability Threshold &
3 & 2 & 0 & 1 & 2 & 3 \\ %
\hhline{~|-||---||---}
&
No APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\ %
\hhline{~|-||---||---} & APE Threshold w/o Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\
\hhline{~-||---||---}
&
APE Threshold w/ Probability Threshold &
2 & 3 & 1 & 0 & 2 & 3 \\
\hhline{~-||---||---}
\end{tabular}
\end{table}
\end{document}