# Using \\ for linebreak in table cell resulting in extended priting of \midrule and \toprule

I am using \thread{} for printing a column name and using \\ for a line break inside a thread. This is resulting in the extended printing of \midrule and \toprule as shown below in the figure.

The code I am using is given below

\begin{figure}[!h]
\begin{tabular}
{p{\dimexpr0.60\linewidth-2\tabcolsep}
p{\dimexpr0.40\linewidth-2\tabcolsep}}
\includegraphics[width=1\linewidth,valign=c]{../matlab/SCEP_mcep_compare/graphs/IotServerCpuUtilization}
&
\centering
\begin{tabularx}{\textwidth}{l r c}
\toprule
\thead{$\lambda$ }  & \thead{Process \\ CPU \% } & \thead{System \\ CPU \%  }  \\
\midrule
10   &  13 &  3     \\
500  &  70 &  30    \\
1000 &  83 &  38    \\
2000 &  84 &  39    \\
3000 &  84 &  39    \\
\bottomrule
\end{tabularx}
\tabularnewline \vspace*{-4mm}
\caption{Effect of $\lambda$ CPU and Memory}\label{fig:SCEPQoS0MemoryCPU}
& \vspace*{-4mm}
\captionof{table}{Values for \cref{fig:SCEPQoS0MemoryCPU}}\label{tab:SCEPQoS0MemoryCPU}
\end{tabular}\vspace*{-13mm}
\end{figure}


What am I doing wrong?

• You are using tabularx without an X-column. Either use tabular (and don't specify a width), or use tabularx (with a width like \linewidth) and an X-column. – Werner Jun 26 '18 at 16:59
• \thead{} not \thread{}. – AML Jun 26 '18 at 17:04

tabularx requires a width component and sets the table to have that width. If you don't have an X-column, columns are set left-to-right using their natural width which may lead to incomplete horizontal usage (as in your case), or content spilling over the pre-specified width. Below I show the intended use - width and an X-column:

\documentclass{article}

\usepackage{tabularx,booktabs,caption,makecell}

\begin{document}

\begin{figure}
\begin{tabular}{
p{\dimexpr0.60\linewidth-2\tabcolsep}
p{\dimexpr0.40\linewidth-2\tabcolsep}
}
\includegraphics[width = \linewidth, valign = c]{example-image}
&
\centering
\begin{tabularx}{\linewidth}{X r c}
\toprule
\thead{$\lambda$} & \thead{Process \\ CPU \%} & \thead{System \\ CPU \%} \\
\midrule
10   &  13 &  3  \\
500  &  70 &  30 \\
1000 &  83 &  38 \\
2000 &  84 &  39 \\
3000 &  84 &  39 \\
\bottomrule
\end{tabularx}
\tabularnewline
\captionof{table}{Effect of $\lambda$ CPU and Memory}
&
\captionof{table}{Values for something}
\end{tabular}
\end{figure}

\end{document}