# How can I draw this complex table in LaTeX?

How can I draw the following table in LaTeX?

I tried this code, but it was not so good:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{a4paper,left=3.5cm,right=3.5cm,top=3cm,bottom=3cm}

\begin{document}

\begin{table}[h!]
\caption{A complex example for handling tables.}
\centering
Coefficients of friction\\
\begin{tabular}{||c|l|l|c|l||}
\hline\hline \multicolumn{2}{||c|} { Static friction } &  & \multicolumn{2}{|c||} { Sliding friction } \\
\cline { 1 - 5} dry and clean & lubricated &  & dry and clean & lubricated \\
\hline \hline $0.15$ & $0.111$ & steel on steel & $0.14$ & $0.001$ \\
$0.19$ & $0.1$ & steel on iron & $0.18$ & $0.001$ \\
\hline\hline
\end{tabular}
\label{tab:my_label}

\end{table}

\end{document}

• What do you mean. The code produce exactly the same that you show, excepting the vertical spaces before/after the fake caption. BTW, with respect the jailed style, a suggested reading: booktabs – Fran May 8 at 20:35
• Slightly unrelated comment: Your static, lubricated steel on iron value has fewer digits behind the comma than the steel on steel value. Guessing from the sliding friction you have 3 significant digits for the lubricated values, so you should probably write 0.100 instead of 0.1. This usually happens when excel (or some other program) cuts the trailing 0s behind the comma off. – And May 10 at 9:38

I'd like to propose you choose a layout that's quite different from the screenshot shown in your query. While that layout features a certain hierarchy of objects, the multitude of line styles give it a rather busy and cluttered, even baroque, "look", with the material in the table's header looking quite cramped -- uncomfortably so, in fact.

I would like to propose using a less cluttered look, one which invites your readers to linger a while and actually study and absorb the table's contents.

\documentclass{article}
\usepackage{array,booktabs,siunitx}
\newcolumntype{T}[1]{S[table-format=#1]}
\usepackage[skip=0.333\baselineskip]{caption}
\begin{document}
\begin{table}
\caption{A complex example for handling tables}
\centering
\begin{tabular}{@{} l *{2}{T{1.2}T{1.3}} @{}}
\toprule
Material pairings & \multicolumn{4}{c@{}}{Coefficients of friction}\\
\cmidrule(l){2-5}
& \multicolumn{2}{c}{Static friction}
& \multicolumn{2}{c@{}}{Sliding friction} \\
\cmidrule(lr){2-3} \cmidrule(l){4-5}
& {dry and clean} & {lubricated} & {dry and clean} & {lubricated} \\
\midrule
Steel on steel & 0.15 & 0.111 & 0.14 & 0.001 \\
Steel on iron  & 0.19 & 0.1   & 0.18 & 0.001 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}


You can use \hhline to get the desired borders:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{geometry}
\usepackage{hhline}
\geometry{a4paper,left=3.5cm,right=3.5cm,top=3cm,bottom=3cm}

\begin{document}

\begin{table}[h!]
\caption{A complex example for handling tables.}
\centering
Coefficients of friction\\
\begin{tabular}{||c|l|l|c|l||}
\hhline{|t:=====:t|}
\multicolumn{2}{||c|}{Static friction}         &               & \multicolumn{2}{|c||}{Sliding friction} \\
\hhline{||--|~|--||}
dry and clean    & lubricated &                & dry and clean & lubricated  \\
\hhline{|:=|=|=|=|=:|}
$0.15$           & $0.111$    & steel on steel & $0.14$        & $0.001$ \\
\hhline{||~|~|~|~|~||}
$0.19$           & $0.1$      & steel on iron  & $0.18$        & $0.001$ \\
\hhline{|b:=====:b|}
\end{tabular}
\label{tab:my_label}
\end{table}

\end{document}


I'd rather use booktabs, which looks much cleaner and much more professional:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{geometry}
\usepackage{booktabs}
\usepackage{longtable}
\geometry{a4paper,left=3.5cm,right=3.5cm,top=3cm,bottom=3cm}

\begin{document}
\begin{longtable}{@{}lllll@{}}
\caption{Coefficients of friction}
\label{tab:my-table}\\
\toprule
\multicolumn{2}{c}{Static friction} &                         & \multicolumn{2}{c}{Sliding friction} \\* \cmidrule(r){1-2} \cmidrule(l){4-5}
%
%
\bottomrule
\endfoot
%
\endlastfoot
%
dry and clean      & lubricated     &                         & dry and clean      & lubricated      \\
0.15               & 0.111          & \textit{steel on steel} & 0.14               & 0.001           \\
0.19               & 0.1            & \textit{steel on iron}  & 0.18               & 0.001           \\* \bottomrule
\end{longtable}

\end{document}


Insert the table inside a \fbox.

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}

\usepackage{geometry}
\geometry{a4paper,left=3.5cm,right=3.5cm,top=3cm,bottom=3cm}

\begin{document}

\begin{table}[h!]
\caption{A complex example for handling tables.}
\vspace{20pt}
\centering
Coefficients of friction\\[2ex]
\fbox{\begin{tabular}{|c|l|l|c|l|} \hline
\multicolumn{2}{|c|}{Static friction} &  & \multicolumn{2}{|c|}{Sliding friction} \\ \cline {1-2} \cline{4-5}
dry and clean & lubricated &  & dry and clean & lubricated \\ \hline \hline
$0.15$ & $0.111$ & steel on steel & $0.14$ & $0.001$ \\
$0.19$ & $0.1$ & steel on iron & $0.18$ & $0.001$ \\ \hline
\end{tabular}}
\label{tab:my_label}
%
\end{table}

\end{document}


Lots of dividing lines make a table look cluttered and less readable. Vertical lines should rarely be used and only if absolutely necessary. White space is usually sufficient to separate information. When organizing, think about how someone will use the table. Since coefficients are looked up by material, put that category on the left. Numerical data should be lined up at the decimal point. I used \phantom{} to make all numbers centered with three digits after the decimal point, but you could also use the S column type in the siunitx package. I also moved the title to the caption, where it belongs.

Note: Some values in your table are incorrect, but I did not edit numbers for the sake of this example.

Here is the code that produced the above figure:

\documentclass[12pt]{article}

\usepackage{booktabs}

\begin{document}

\begin{table}[h!]
\caption{Coefficients of friction}
\begin{center}
\begin{tabular}{lcccc}
{}    &\multicolumn{2}{c}{Static}    &\multicolumn{2}{c}{Sliding}\\
\cmidrule(lr){2-3}\cmidrule(lr){4-5}
Material & Dry and clean & Lubricated & Dry and clean & Lubricated\\
\hline
Steel on steel    &0.15\phantom{0}    &0.111    &0.14\phantom{0}    &0.001\\
Steel on iron    &0.19\phantom{0}    &0.1\phantom{00}    &0.18\phantom{0}    &0.001
\end{tabular}
\end{center}
\label{tab:my_label}
\end{table}%

\end{document}