1

I want to create table like this . enter image description here

I don't know how to create header of table like that. This is Latex script.

\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*}

When I run script the table width out of page like this. How to set long word to next line and merge some column. enter image description here

  • Could you please turn your code fragment inot a compilable minimal working example (MWE) by adding the relevant packages and the documentclass you use? Regarding linebreaks in table cells, you might be interested in the makecell package. – leandriis Mar 15 at 19:37
2

Here is a slightly different suggestion using makecell in combination with a smaller fontsize. I have also added the first row of the table using \multicolumn and vertically centered the first cell using \multirow. The following example contains a second table without vertical lines. There I have used the horizontal rules from the booktabs package and slightly decreased the \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}

enter image description here

2

We can make such a table fit the page, not only using linebreaks with makecell, buut also reducing the value of \tabcolsep (6pt by default) and loading geometry to have more decent margins (if you don't use marginal notes). I added a demonstration of the use of \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} 

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.