각 셀의 텍스트를 세로 중앙에 배치하고 싶습니다.
\documentclass[12pt,a4paper,onesided]{report}
\usepackage{array}
\usepackage{booktabs}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\begin{document}
\begin{table}[htbp]
\centering
\caption{Recognition with Haar Wavelet based image compression for $N=5$ features}
\label{tab: Recognition with Haar Wavelet based image compression for $N=5$ features}
\begin{tabular}{|C{1.8cm}||C{1.8cm}||C{2cm}||C{1.8cm}|C{1.8cm}||C{1.8cm}||C{2.5cm}|}
\toprule \bfseries Training folder
&\bfseries Training Time
&\bfseries Training Accuracy
& \multicolumn{2}{c|}{\bfseries Number of images}
&\bfseries Testing folder
& \bfseries Recognition accuracy\\
& & & \bfseries Training &\bfseries Testing & &\\ \midrule
1 & 0.52 & 70.00 & 10 & 90 & 9 & 14.44 \\
2 & 0.66 & 85.00 & 20 & 80 & 8 & 38.75 \\
3 & 0.74 & 86.66 & 30 & 70 & 7 & 40.00 \\
4 & 0.68 & 85.00 & 40 & 60 & 6 & 48.33 \\
5 & 0.88 & 88.00 & 50 & 50 & 5 & 62.00 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
답변1
새로운 열 유형을 정의하거나 열 너비를 계산하지 않는 솔루션입니다. 이중선 모양을 개선하려면 makecell
, caption
및 multirow
패키지와 plus 를 사용하기만 하면 됩니다 . hhline
표는 두 가지 방법으로 여백에 맞출 수 있습니다. tabcolsep
4pt로 줄이고 문서에 더 작은 글꼴 크기를 사용하거나(11pt의 예를 제공합니다) 글꼴 크기를 locally
10pt로 줄입니다( \small
12pt의 명령이 가능합니다).
그런데 booktabs
수직선에는 사용하지 마세요.
\documentclass[11pt,a4paper,onesided]{report}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe, nomarginpar, left=1.5in, right=1in, top=1.5in, bottom=1in,]{geometry}
\usepackage{array}
\usepackage[font = small]{caption}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}
\renewcommand{\theadalign}{cc}
\setlength{\tabcolsep}{4pt}
\usepackage{hhline}
\begin{document}
Table fontsize: 11 pt
\begin{table}[htbp]
\centering
\caption{Recognition with Haar Wavelet based image compression for $N=5$ features}
\label{tab: Recognition with Haar Wavelet based image compression for $N=5$ features}
\begin{tabular}{*{3}{|c|}|cc|*{2}{|c|}}%{|C{1.8cm}||C{1.8cm}||C{2cm}||C{1.8cm}|C{1.8cm}||C{1.8cm}||C{2.5cm}|}
\hhline{|-||-||-||--||-||-|}
\multirowthead{2}{Training\\ Folder}
&\multirowthead{2}{Training\\ Time}
&\multirowthead{2}{Training\\ Accuracy}
& \multicolumn{2}{c||}{\thead{Number of images}}
&\multirowthead{2}{Testing\\ Folder}
& \multirowthead{2}{Recognition\\ Accuracy}\\
& & & \thead*{Training} & \thead{Testing} & &\\
\hhline{|-||-||-||--||-||-|}
\Gape[6pt][0pt]{1} & 0.52 & 70.00 & 10 & 90 & 9 & 14.44 \\
2 & 0.66 & 85.00 & 20 & 80 & 8 & 38.75 \\
3 & 0.74 & 86.66 & 30 & 70 & 7 & 40.00 \\
4 & 0.68 & 85.00 & 40 & 60 & 6 & 48.33 \\
\Gape[0pt][6pt]{5} & 0.88 & 88.00 & 50 & 50 & 5 & 62.00 \\
\hhline{|-||-||-||--||-||-|}
\end{tabular}
\end{table}
\fontsize{12}{14}\selectfont
Table font size: 10 point
\begin{table}[htbp]
\small
\centering
\caption{Recognition with Haar Wavelet based image compression for $N=5$ features}
%\small
\label{tab: Recognition with Haar Wavelet based image compression for $N=5$ features}
\begin{tabular}{*{3}{|c|}|cc|*{2}{|c|}}%{|C{1.8cm}||C{1.8cm}||C{2cm}||C{1.8cm}|C{1.8cm}||C{1.8cm}||C{2.5cm}|}
\hhline{|-||-||-||--||-||-|}
\multirowthead{2}{Training\\ Folder}
&\multirowthead{2}{Training\\ Time}
&\multirowthead{2}{Training\\ Accuracy}
& \multicolumn{2}{c||}{\thead{Number of images}}
&\multirowthead{2}{Testing\\ Folder}
& \multirowthead{2}{Recognition\\ Accuracy}\\
& & & \thead*{Training} & \thead{Testing} & &\\
\hhline{|-||-||-||--||-||-|}
\Gape[6pt][0pt]{1} & 0.52 & 70.00 & 10 & 90 & 9 & 14.44 \\
2 & 0.66 & 85.00 & 20 & 80 & 8 & 38.75 \\
3 & 0.74 & 86.66 & 30 & 70 & 7 & 40.00 \\
4 & 0.68 & 85.00 & 40 & 60 & 6 & 48.33 \\
\Gape[0pt][6pt]{5} & 0.88 & 88.00 & 50 & 50 & 5 & 62.00 \\
\hhline{|-||-||-||--||-||-|}
\end{tabular}
\end{table}
\end{document}
답변2
이것이 당신이 요청한 것입니까? 여기서 솔루션은 텍스트를 왼쪽 정렬된 두 줄로 래핑하는 구조 \mc
에 대한 인수로 텍스트를 사용하는 매크로를 정의합니다.multirow
\newcommand\mc[1]{\multicolumn{1}{l||}{\multirow{2}{0.9cm}{#1}}}
암호
\documentclass[12pt,a4paper]{report}
\usepackage{array,graphicx}
\usepackage[margin=1cm]{geometry}
\usepackage{booktabs,dcolumn,multirow}
\newcolumntype{C}[1]{>{\centering \arraybackslash\hspace{0pt}}m{#1}}
\newcommand\mc[1]{\multicolumn{1}{l||}{\multirow{2}{0.9cm}{#1}}}
\begin{document}
Before:
\begin{table}[htbp]
\centering
\caption{Recognition with Haar Wavelet based image compression for $N=5$ features}
\label{tab: Recognition with Haar Wavelet based image compression for $N=5$ features}
\begin{tabular}{|C{1.8cm}||C{1.8cm}||C{2cm}||C{1.8cm}|C{1.8cm}||C{1.8cm}||C{2.5cm}|}
\toprule \bfseries Training folder
&\bfseries Training Time
&\bfseries Training Accuracy
& \multicolumn{2}{c|}{\bfseries Number of images}
&\bfseries Testing folder
& \bfseries Recognition accuracy\\
& & & \bfseries Training &\bfseries Testing & &\\ \midrule
1 & 0.52 & 70.00 & 10 & 90 & 9 & 14.44 \\
2 & 0.66 & 85.00 & 20 & 80 & 8 & 38.75 \\
3 & 0.74 & 86.66 & 30 & 70 & 7 & 40.00 \\
4 & 0.68 & 85.00 & 40 & 60 & 6 & 48.33 \\
5 & 0.88 & 88.00 & 50 & 50 & 5 & 62.00 \\
\bottomrule
\end{tabular}
\end{table}
After:
\begin{table}[htbp]
\centering
\resizebox{\textwidth}{!}{ % if resizebox is needed
\begin{minipage}{\textwidth} % if resizebox is needed
\caption{Recognition with Haar Wavelet based image compression for $N=5$ features}
\label{tab: Recognition with Haar Wavelet based image compression for $N=5$ features}
\begin{tabular}{|C{1.8cm}||C{1.8cm}||C{2cm}||C{1.8cm}|C{1.8cm}||C{1.8cm}||C{2.5cm}|}
\toprule
\multicolumn{1}{|l||}{\multirow{2}{0.9cm}{\bfseries Training folder}}
&\mc{\bfseries Training Time}
&\mc{\bfseries Training Accuracy}
&\multicolumn{2}{c||}{\bfseries Number of images}
&\mc{\bfseries Testing folder}
&\multicolumn{1}{l|}{\multirow{2}{0.9cm}{\bfseries Recognition accuracy}} \\
& & & \bfseries Training &\bfseries Testing & &\\
\midrule
1 & 0.52 & 70.00 & 10 & 90 & 9 & 14.44 \\
2 & 0.66 & 85.00 & 20 & 80 & 8 & 38.75 \\
3 & 0.74 & 86.66 & 30 & 70 & 7 & 40.00 \\
4 & 0.68 & 85.00 & 40 & 60 & 6 & 48.33 \\
5 & 0.88 & 88.00 & 50 & 50 & 5 & 62.00 \\
\bottomrule
\end{tabular}
\end{minipage} % if resizebox is needed
} % if resizebox is needed
\end{table}
\end{document}