LaTeX 表格超出頁數

LaTeX 表格超出頁數

我想創建這樣的表。 在此輸入影像描述

我不知道如何創建這樣的表頭。這是乳膠腳本。

\begin{table*}
\centering
\caption{Some Typical Commands}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|l|} \hline
Product ID&A&Specify Size&Error(\%)&A&Specify Size&Error(\%)&A&Specify Size&Error(\%)\\ \hline
1&Method new&6&11.70&Method+Data&No&3.24&Method+Data&6&10.55\\ \hline
2&A& 1\\ \hline
3&B& 1\\ \hline
4&A& 1\\ \hline
5&B& 1\\ \hline
6&A& 1\\ \hline
7&B& 1\\ \hline
8&A& 1\\ \hline
9&B& 1\\ \hline
10&A& 1\\ \hline\end{tabular}
\end{table*}

當我運行腳本時,表格寬度超出頁面,如下所示。如何將長單字設定到下一行並合併某些列。 在此輸入影像描述

答案1

makecell這是與較小字體結合使用的稍微不同的建議。我還使用 新增了表格的第一行\multicolumn,並使用 使第一個儲存格垂直居中\multirow。以下範例包含第二個沒有垂直線的表格。在那裡,我使用了包中的水平規則booktabs,並稍微減少了\tabcolsep.

\documentclass{article}
\usepackage{geometry}
\usepackage{makecell}
\usepackage{multirow}

\usepackage{booktabs}
\begin{document}

\begin{table*}
\small
\centering
\caption{Some Typical Commands}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|l|} \hline
\multirow{3}{*}{\makecell[cc]{Product \\ ID}} & \multicolumn{3}{c|}{1} & \multicolumn{3}{c|}{2} & \multicolumn{3}{c|}{3}\\ \cline{2-10}
 & A & \makecell[cc]{Specify\\ Size} & \makecell[cc]{Error\\(\%)} & A & \makecell[cc]{Specify\\ Size} & \makecell[cc]{Error\\(\%)}& A & \makecell[cc]{Specify\\ Size} & \makecell[cc]{Error\\(\%)}\\ \hline
1 & \makecell[cc]{Method \\new} & 6&11.70 & \makecell{Method+\\Data} & No & 3.24 & \makecell{Method+\\Data} & 6 & 10.55\\ \hline
2&A& 1 &  &  &  &  &  &  & \\ \hline
3&B& 1 &  &  &  &  &  &  & \\ \hline
4&A& 1 &  &  &  &  &  &  & \\ \hline
5&B& 1 &  &  &  &  &  &  & \\ \hline
6&A& 1 &  &  &  &  &  &  & \\ \hline
7&B& 1 &  &  &  &  &  &  & \\ \hline
8&A& 1 &  &  &  &  &  &  & \\ \hline
9&B& 1 &  &  &  &  &  &  & \\ \hline
10&A& 1 &  &  &  &  &  &  & \\ \hline\end{tabular}
\end{table*}



\begin{table*}
\setlength{\tabcolsep}{5pt}
\centering
\caption{Some Typical Commands}
\begin{tabular}{cccccccccl} \toprule
\multirow{3.25}{*}{\makecell[cc]{Product \\ ID}} & \multicolumn{3}{c}{1} & \multicolumn{3}{c}{2} & \multicolumn{3}{c}{3}\\
\cmidrule(lr){2-4}  \cmidrule(lr){5-7} \cmidrule(lr){8-10}
& A & \makecell[cc]{Specify\\ Size} & \makecell[cc]{Error\\(\%)} & A & \makecell[cc]{Specify\\ Size} & \makecell[cc]{Error\\(\%)}& A & \makecell[cc]{Specify\\ Size} & \makecell[cc]{Error\\(\%)}\\ \midrule
1 & \makecell[cc]{Method \\new} & 6&11.70 & \makecell{Method+\\Data} & No & 3.24 & \makecell{Method+\\Data} & 6 & 10.55\\ 
2&A& 1\\ 
3&B& 1\\ 
4&A& 1\\ 
5&B& 1\\ 
6&A& 1\\ 
7&B& 1\\ 
8&A& 1\\ 
9&B& 1\\ 
10&A& 1\\ \bottomrule
\end{tabular}
\end{table*}

\end{document}

在此輸入影像描述

答案2

我們可以使這樣的表格適合頁面,不僅使用 的換行符makecell,而且還減少 的值\tabcolsep(預設為 6pt)並加載geometry以獲得更合適的邊距(如果您不使用邊注)。我添加了使用的演示\multicolumn

\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[showframe]{geometry}
\usepackage{caption, makecell}

\begin{document}

\begin{table*}
\centering
\setlength{\tabcolsep}{3pt}
\setlength{\extrarowheight}{2pt}
\renewcommand{\theadfont}{\footnotesize\bfseries}
\caption{Some Typical Commands}
\begin{tabular}{|*9{c|}l|} \hline
\thead{Product\\ ID} & \thead{A} & \thead{Specify\\ Size} & \thead{Error \\ (\%)} & \thead{A } & \thead{Specify \\ Size} & \thead{Error\\(\%)}& \thead{A} & \thead{Specify\\ Size} & \thead{Error\\ (\%)} \\ \hline
1 & \makecell{Method\\\ new} & 6 &11.70 & \makecell{Method\\+Data} & No & 3.24 & \makecell{Method\\ +Data}& 6 & 10.55 \\ \hline
2&A& 1 & & \multicolumn{3}{c|}{} &\multicolumn{3}{c|}{} \\ \hline
3&B& 1 & & & & & & &\\ \hline
4&A& 1 & & & & & & &\\ \hline
5&B& 1 & & & & & & & \\ \hline
6&A& 1 & & & & & & &\\ \hline
7&B& 1 & & & & & & &\\ \hline
8&A& 1 & & & & & & &\\ \hline
9&B& 1 & & & & & & &\\ \hline
10&A& 1 & & & & & & &\\ \hline
\end{tabular}
\end{table*}

\end{document} 

在此輸入影像描述

相關內容