2

I wrote a code like the one below:

\begin{table}
% table caption is above the table
\caption{Sample}
\label{tab:2}       % Give a unique label
% For LaTeX tables use
\begin{tabular}{c|c|p{2cm}|p{2cm}|p{2cm}|p{2cm}}
\hline\noalign{\smallskip}
{Task size} & {Type} & \multicolumn{2}{c}{{Makespan}} & 
\multicolumn{2}{c}{{Execution Cost }}
 \\ \hline
{}&{}& X & Y & X & Y \\
\noalign{\smallskip}\hline\noalign{\smallskip}
 \multirow{4}{*}{100} & A & 6 & 4 &10&11 \\
 & B & 6 & 4 &10&11 \\
 & C & 6 & 4 &10&11 \\
 & D & 6 & 4  &10&11\\ \hline
\multirow{4}{*}{200} & A & 6 & 4 &10&11  \\
 & B & 6 & 4  &10&11\\
 & C & 6 & 4  &10&11\\
 & D & 6 & 4  &10&11\\ \hline
 \multirow{4}{*}{300} & A & 6 & 4  &10&11 \\
 & B & 6 & 4  &10&11\\
 & C & 6 & 4 &10&11 \\
 & D & 6 & 4  &10&11\\ \hline
 \multirow{4}{*}{400} & A & 6 & 4  &10&11 \\
 & B & 6 & 4  &10&11\\
 & C & 6 & 4  &10&11\\
 & D & 6 & 4 &10&11 \\ \hline
\noalign{\smallskip}\hline
\end{tabular}
\end{table}

enter image description here and I wish to take away the horizontal lines in the first and second columns that come under the names, and the 'p' used for column size is not giving the actual dimensions. Any help is really appreciated.

1
  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. Nov 18, 2015 at 13:32

1 Answer 1

3

Some suggestions:

  • Get rid of all vertical rules and most horizontal rules in the table. All those lines don't really improve legibility -- in fact, they add a lot of visual clutter that may reduce legibility...

  • Load the booktabs package and use its \toprule, midrule, \bottomrule, and \cmidrule macros to get well-spaced horizontal rules.

  • Your table, with its four p columns, is actually (slightly) too wide for the text block. Consider using a tabularx environment and setting its width to \textwidth; then, let LaTeX do all the tedious work related to calculating column widths.

enter image description here

\documentclass{article}
\usepackage{booktabs,tabularx,caption}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of "X" column type 
\begin{document}

\begin{table}
\caption{Sample}
\label{tab:2} 

\begin{tabularx}{\textwidth}{ll CCCC }
\toprule
Task size & Type & \multicolumn{2}{c}{Makespan} & \multicolumn{2}{c}{Execution Cost} \\
\cmidrule(lr){3-4} \cmidrule(l){5-6}
& & XXX & YYY & XXX & YYY \\
\midrule
100 & A & 6 & 4 &10&11 \\
    & B & 6 & 4 &10&11 \\
    & C & 6 & 4 &10&11 \\
    & D & 6 & 4 &10&11 \\\addlinespace
100 & A & 6 & 4 &10&11 \\
    & B & 6 & 4 &10&11 \\
    & C & 6 & 4 &10&11 \\
    & D & 6 & 4 &10&11 \\\addlinespace
100 & A & 6 & 4 &10&11 \\
    & B & 6 & 4 &10&11 \\
    & C & 6 & 4 &10&11 \\
    & D & 6 & 4 &10&11 \\\addlinespace
100 & A & 6 & 4 &10&11 \\
    & B & 6 & 4 &10&11 \\
    & C & 6 & 4 &10&11 \\
    & D & 6 & 4 &10&11 \\
\bottomrule
\end{tabularx}
\end{table}
\end{document} 
1
  • Thank you very much Mico for introducing me to the 'booktabs' package. The answer is really very helpful.
    – user13522
    Nov 19, 2015 at 5:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .