我需要使用 LaTeX 创建类似的表格:
我曾尝试使用\tabular
和\multicolumn
,但每次都会出错。
有人能帮助我吗?
\documentclass{article}
\begin{document}
\begin{tabular}{ | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | l | }
\hline
\ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ \\ \hline
\ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ & \ \\ \hline
& & No 0 & & & & & No 1 & & & & & No 2 & & & & & No 3 & & & & \\ \hline
& & TT & FF & P & R & F & TT & FF & P & R & F & TT & FF & P & R & F & TP & FP & P & R & F \\ \hline
A & A1 & 2 & 3 & 0.4 & 0.4 & 0.4 & 3 & 7 & 0.3 & 0.6 & 0.54 & 5 & 12 & 0.28 & 1 & 0.79 & 5 & 0 & 1 & 1 & 1 \\ \hline
& A2 & 1 & 12 & 0.08 & 0.5 & 0.31 & 2 & 14 & 0.13 & 1 & 0.56 & 2 & 4 & 0.33 & 1 & 0.82 & 2 & 0 & 1 & 1 & 1 \\ \hline
& A3 & 0 & 0 & na & na & 0 & 0 & 4 & 0 & na & 0 & 0 & 0 & na & na & na & 0 & 0 & na & na & na \\ \hline
B & B1 & 2 & 9 & 0.18 & 0.5 & 0.42 & 3 & 26 & 0.12 & 0.75 & 0.47 & 4 & 30 & 0.12 & 1 & 0.54 & 4 & 0 & 1 & 1 & 1 \\ \hline
& B2 & 0 & 3 & 0 & 0 & na & 1 & 3 & 0.25 & 0.5 & 0.45 & 2 & 2 & 0.5 & 1 & 0.9 & 2 & 0 & 1 & 1 & 1 \\ \hline
& B3 & 0 & 1 & 0 & 0 & na & 1 & 3 & 0.25 & 1 & 0.75 & 1 & 2 & 0.33 & 1 & 0.82 & 1 & 0 & 1 & 1 & 1 \\ \hline
C & C1 & 1 & 56 & 0.02 & 1 & 0.14 & 1 & 38 & 0.03 & 1 & 0.19 & 1 & 11 & 0.08 & 1 & 0.45 & 1 & 0 & 1 & 1 & 1 \\ \hline
& C2 & 0 & 8 & 0 & 0 & na & 1 & 1 & 0.5 & 1 & 0.9 & 1 & 1 & 0.5 & 1 & 0.9 & 1 & 0 & 1 & 1 & 1 \\ \hline
& C3 & 0 & 2 & 0 & 0 & na & 0 & 7 & 0 & 0 & na & 1 & 4 & 0.2 & 1 & 0.69 & 1 & 0 & 1 & 1 & 1 \\ \hline
D & D1 & 0 & 37 & 0 & 0 & na & 2 & 16 & 0.11 & 0.33 & 0.27 & 3 & 18 & 0.14 & 0.5 & 0.39 & 3 & 0 & 1 & 1 & 0.53 \\ \hline
& D2 & 0 & 2 & 0 & 0 & na & 3 & 2 & 0.4 & 0.5 & 0.49 & 4 & 2 & 0.67 & 1 & 0.95 & 4 & 0 & 1 & 1 & 1 \\ \hline
& D3 & 0 & 0 & na & na & 0 & 0 & 6 & 0 & na & 0 & 0 & 1 & 0 & na & na & 0 & 0 & na & na & na \\ \hline
\end{tabular}
\end{document}
答案1
这灵感来自于Bernard 给出的答案使用makecell
。我之所以使用这个,是因为看起来使用垂直规则对于这个问题所期望的外观至关重要,并且排除了使用booktabs
。像 一样booktabs
,makecell
为 LaTeX 相当扁平的默认表格布局添加了一些额外的间距,并支持使用可变宽度规则。
买者自负...由于我以前从未使用过此包,因此代码可能会受到影响。
如果不减小尺寸(无论使用什么包),表格就无法水平放置,因此它以横向排版:
\documentclass{article}
\usepackage{multirow,makecell}
\renewcommand{\theadfont}{\bfseries}
\usepackage{pdflscape}
\begin{document}
\begin{landscape}
\noindent\begin{tabular}{ !{\vrule width1.2pt}c!{\vrule width1.2pt}c!{\vrule width1.2pt}*{5}{c}!{\vrule width1.2pt}*{5}{c}!{\vrule width1.2pt}*{5}{c}!{\vrule width1.2pt}*{5}{c}!{\vrule width1.2pt} }
\Xcline{3-22}{1.2pt}
\multicolumn{2}{c!{\vrule width1.2pt}}{} & \multicolumn{5}{c!{\vrule width1.2pt}}{\thead{No 0}} & \multicolumn{5}{c!{\vrule width1.2pt}}{\thead{No 1}} & \multicolumn{5}{c!{\vrule width1.2pt}}{\thead{No 2}} & \multicolumn{5}{c!{\vrule width1.2pt}}{\thead{No 3}} \\\Xcline{3-22}{1.2pt}
\multicolumn{2}{c!{\vrule width1.2pt}}{} & \thead{TT} & \thead{FF} & \thead{P} & \thead{R} & \thead{F} & \thead{TT} & \thead{FF} & \thead{P} & \thead{R} & \thead{F} & \thead{TT} & \thead{FF} & \thead{P} & \thead{R} & \thead{F} & \thead{TP} & \thead{FP} & \thead{P} & \thead{R} & \thead{F} \\\Xhline{1.2pt}
\multirowthead{3}{A} & \thead{A1} & 2 & 3 & 0.4 & 0.4 & 0.4 & 3 & 7 & 0.3 & 0.6 & 0.54 & 5 & 12 & 0.28 & 1 & 0.79 & 5 & 0 & 1 & 1 & 1 \\\Xcline{2-2}{1.2pt}
& \thead{A2} & 1 & 12 & 0.08 & 0.5 & 0.31 & 2 & 14 & 0.13 & 1 & 0.56 & 2 & 4 & 0.33 & 1 & 0.82 & 2 & 0 & 1 & 1 & 1 \\\Xcline{2-2}{1.2pt}
& \thead{A3} & 0 & 0 & na & na & 0 & 0 & 4 & 0 & na & 0 & 0 & 0 & na & na & na & 0 & 0 & na & na & na \\\Xhline{1.2pt}
\multirowthead{3}{B} & \thead{B1} & 2 & 9 & 0.18 & 0.5 & 0.42 & 3 & 26 & 0.12 & 0.75 & 0.47 & 4 & 30 & 0.12 & 1 & 0.54 & 4 & 0 & 1 & 1 & 1 \\\Xcline{2-2}{1.2pt}
& \thead{B2} & 0 & 3 & 0 & 0 & na & 1 & 3 & 0.25 & 0.5 & 0.45 & 2 & 2 & 0.5 & 1 & 0.9 & 2 & 0 & 1 & 1 & 1 \\\Xcline{2-2}{1.2pt}
& \thead{B3} & 0 & 1 & 0 & 0 & na & 1 & 3 & 0.25 & 1 & 0.75 & 1 & 2 & 0.33 & 1 & 0.82 & 1 & 0 & 1 & 1 & 1 \\\Xhline{1.2pt}
\multirowthead{3}{C} & \thead{C1} & 1 & 56 & 0.02 & 1 & 0.14 & 1 & 38 & 0.03 & 1 & 0.19 & 1 & 11 & 0.08 & 1 & 0.45 & 1 & 0 & 1 & 1 & 1 \\\Xcline{2-2}{1.2pt}
& \thead{C2} & 0 & 8 & 0 & 0 & na & 1 & 1 & 0.5 & 1 & 0.9 & 1 & 1 & 0.5 & 1 & 0.9 & 1 & 0 & 1 & 1 & 1 \\\Xcline{2-2}{1.2pt}
& \thead{C3} & 0 & 2 & 0 & 0 & na & 0 & 7 & 0 & 0 & na & 1 & 4 & 0.2 & 1 & 0.69 & 1 & 0 & 1 & 1 & 1 \\\Xhline{1.2pt}
\multirowthead{3}{D}& \thead{D1} & 0 & 37 & 0 & 0 & na & 2 & 16 & 0.11 & 0.33 & 0.27 & 3 & 18 & 0.14 & 0.5 & 0.39 & 3 & 0 & 1 & 1 & 0.53 \\\Xcline{2-2}{1.2pt}
& \thead{D2} & 0 & 2 & 0 & 0 & na & 3 & 2 & 0.4 & 0.5 & 0.49 & 4 & 2 & 0.67 & 1 & 0.95 & 4 & 0 & 1 & 1 & 1 \\\Xcline{2-2}{1.2pt}
& \thead{D3} & 0 & 0 & na & na & 0 & 0 & 6 & 0 & na & 0 & 0 & 1 & 0 & na & na & 0 & 0 & na & na & na \\\Xhline{1.2pt}
\end{tabular}
\end{landscape}
\end{document}
答案2
再次(并提供 @cfr 解决方案的替代方案 — 并复制其中的一部分 :P—)。使用tap
。远非完美,但tap
提供了一些灵活性。
\documentclass{scrartcl}
\input{tap}
\usepackage{pdflscape}
\begin{document}
\deftable\tmptable
\begintable
\begintableformat
& \center
\endtableformat
\B"- @2 ! @20 \= \E!
\B": @2 ! @5 \textbf{No 1} ! @5 \textbf{No 2} ! @5 \textbf{No 3} ! @5 \textbf{No 4} \E!
\B"- @2 ! @20 \= \E!
\B": @2 ! \emph{TT} " \emph{FF} " \emph{P} " \emph{R} " \emph{F} ! \emph{TT} " \emph{FF} " \emph{P} " \emph{R} " \emph{F} ! \emph{TT} " \emph{FF} " \emph{P} " \emph{R} " \emph{F} ! \emph{TT} " \emph{FF} " \emph{P} " \emph{R} " \emph{F} \E!
\=
\B!: \textbf{A} ! \textbf{A1} ! 2 " 3 " 0.4 " 0.4 " 0.4 ! 3 " 7 " 0.3 " 0.6 " 0.54 ! 5 " 12 " 0.28 " 1 " 0.79 ! 5 " 0 " 1 " 1 " 1 \E!
\B!- ! \= ! " " " " ! " " " " ! " " " " ! " " " " \E!
\B!: ! \textbf{A2} ! 1 " 12 " 0.08 " 0.5 " 0.31 ! 2 " 14 " 0.13 " 1 " 0.56 ! 2 " 4 " 0.33 " 1 " 0.82 ! 2 " 0 " 1 " 1 " 1 \E!
\B!- ! \= ! " " " " ! " " " " ! " " " " ! " " " " \E!
\B!: ! \textbf{A3} ! 0 " 0 " na " na " 0 ! 0 " 4 " 0 " na " 0 ! 0 " 0 " na " na " na ! 0 " 0 " na " na " na \E!
\=
\B!: \textbf{B} ! \textbf{B1} ! 2 " 9 " 0.18 " 0.5 " 0.42 ! 3 " 26 " 0.12 " 0.75 " 0.47 ! 4 " 30 " 0.12 " 1 " 0.54 ! 4 " 0 " 1 " 1 " 1 \E!
\B!- ! \= ! " " " " ! " " " " ! " " " " ! " " " " \E!
\B!: ! \textbf{B2} ! 0 " 3 " 0 " 0 " na ! 1 " 3 " 0.25 " 0.5 " 0.45 ! 2 " 2 " 0.5 " 1 " 0.9 ! 2 " 0 " 1 " 1 " 1 \E!
\B!- ! \= ! " " " " ! " " " " ! " " " " ! " " " " \E!
\B!: ! \textbf{B3} ! 0 " 1 " 0 " 0 " na ! 1 " 3 " 0.25 " 1 " 0.75 ! 1 " 2 " 0.33 " 1 " 0.82 ! 1 " 0 " 1 " 1 " 1 \E!
\=
\B!: \textbf{C} ! \textbf{C1} ! 1 " 56 " 0.02 " 1 " 0.14 ! 1 " 38 " 0.03 " 1 " 0.19 ! 1 " 11 " 0.08 " 1 " 0.45 ! 1 " 0 " 1 " 1 " 1 \E!
\B!- ! \= ! " " " " ! " " " " ! " " " " ! " " " " \E!
\B!: ! \textbf{C2} ! 0 " 8 " 0 " 0 " na ! 1 " 1 " 0.5 " 1 " 0.9 ! 1 " 1 " 0.5 " 1 " 0.9 ! 1 " 0 " 1 " 1 " 1 \E!
\B!- ! \= ! " " " " ! " " " " ! " " " " ! " " " " \E!
\B!: ! \textbf{C3} ! 0 " 2 " 0 " 0 " na ! 0 " 7 " 0 " 0 " na ! 1 " 4 " 0.2 " 1 " 0.69 ! 1 " 0 " 1 " 1 " 1 \E!
\=
\B!: \textbf{D} ! \textbf{D1} ! 0 " 37 " 0 " 0 " na ! 2 " 16 " 0.11 " 0.33 " 0.27 ! 3 " 18 " 0.14 " 0.5 " 0.39 ! 3 " 0 " 1 " 1 " 0.53 \E!
\B!- ! \= ! " " " " ! " " " " ! " " " " ! " " " " \E!
\B!: ! \textbf{D2} ! 0 " 2 " 0 " 0 " na ! 3 " 2 " 0.4 " 0.5 " 0.49 ! 4 " 2 " 0.67 " 1 " 0.95 ! 4 " 0 " 1 " 1 " 1 \E!
\B!- ! \= ! " " " " ! " " " " ! " " " " ! " " " " \E!
\B!: ! \textbf{D3} ! 0 " 0 " na " na " 0 ! 0 " 6 " 0 " na " 0 ! 0 " 1 " 0 " na " na ! 0 " 0 " na " na " na \E!
\=
\endtable
\begin{landscape}
\mbox{\begintable\tmptable\endtable}
\end{landscape}
\end{document}