Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am beginner of LaTeX. I am using MiKTeX 2.9 and TeXnicCenter as editor. I tried following code to create merged table but I got 101 errors! I want to create PDF file and not able to understand what went wrong. Probably, am I not using correct package? Please help, following is the code:

\documentclass[a4paper,12pt]{article}
\usepackage{tabls}
\usepackage{ctable}
\usepackage{booktabs}
\usepackage{longtable}

\begin{document}
\section{Table 1}

\begin{tabular}{ccc}

\multicolumn{2}{c}{\head{Input}} & \multicolumn{1}{c}{Output}\\

\head{Group A} & \head{Group B} & \head{Group C} \\

cmidrule[2pt](lr){1-2} \cmidrule[1pt](r){3}

30 & 50 & 80\\

10 & 20 & 30\\

1 & 5 & 6\\

\bottomrule[1.5pt]

\end{tabular}
\end{document}

The editor is showing error at first \multicolumn line. It is showing

pdflatex-> !undefined control sequence.

share|improve this question
    
Welcome to TeX.sx! –  texenthusiast Jan 7 '13 at 3:06
    
1. The second \multicolumn is not needed. It does not affect the output. 2. In the actual log, directly following ! Undefined control sequence, you can see that \head is the problem as it gets an own line. –  Qrrbrbirlbel Jan 7 '13 at 4:23
add comment

2 Answers

I am not sure what \head is, so I have defined it below as \textbf.

The only package required for the table below is the booktabs package.

The \cmidrule macro requires a range of columns, so instead of {3} you need to specify {3-3}. You were also missing a \ prior to the first \cmidrule.

enter image description here

Code:

\documentclass[a4paper,12pt]{article} 
%\usepackage{tabls} 
%\usepackage{ctable} 
\usepackage{booktabs} 
%\usepackage{longtable}

\newcommand*{\head}[1]{\textbf{#1}}%

\begin{document} \section{Table 1}

\begin{tabular}{ccc}

\multicolumn{2}{c}{\head{Input}} & \multicolumn{1}{c}{Output}\\
\head{Group A} & \head{Group B} & \head{Group C} \\
\cmidrule[2pt](lr{0.75em}){1-2} \cmidrule[1pt](r){3-3}
30 & 50 & 80\\
10 & 20 & 30\\
 1 &  5 &  6\\
\bottomrule[1.5pt]
\end{tabular} 
\end{document}
share|improve this answer
    
Thanks! Your suggestions worked! Thanks again!! –  user24057 Jan 7 '13 at 4:58
add comment

For beginners, I believe it is useful to see the minimum code necessary to accomplish the spirit of your task. Take a look at this:

\documentclass[a4paper,12pt]{article}

\begin{document}

\begin{tabular}{|cc|c|}
\hline
\multicolumn{2}{|c|}{Input} & \multicolumn{1}{|c|}{Output}\\
\hline
Group A & Group B & Group C \\
\hline
30 & 50 & 80\\
10 & 20 & 30\\
1 & 5 & 6\\
\hline
\end{tabular}
\end{document}

The other packages in your header expand the capabilities of LaTeX's tabular environment. Add them as you reach tabular's limitations (like multiple page tables).

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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