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'm not an expert with the tabular environment...I have some problems:

  1. I got an error "Extra alignment tab has been changed to \cr."
  2. I would like to have the professor name completely to the right.

 \documentclass[12pt,a4paper,oneside]{book}
 \usepackage{array,booktabs,siunitx}
 \begin{document}
 \noindent
 \begin{tabular}{@{}l@{\hspace{.5em}}l r}
 Students: &                    &Professor: &\\
 Name1     &\textsc{Surname}    &Name       &\textsc{Surname} \\
 Name2     &\textsc{Surname}    &           &       \\
 Name3     &\textsc{Surname}    &           &
 \end{tabular}
 \end{document}

Can somebody help me?

share|improve this question
1  
You are specifying 3 columns but actually use 4. add a column like \begin{tabular}{@{}l@{\hspace{.5em}}l r l}. See the last l. –  Harish Kumar Feb 17 '13 at 11:41
add comment

2 Answers

up vote 4 down vote accepted

enter image description here

you had only specified 3 columns but had 4 columns of data, I changed to just use three columns but other layouts are possible depending on how you want it to look...

 \documentclass[12pt,a4paper,oneside]{book}
 \usepackage{array,booktabs,siunitx}
 \begin{document}
 \noindent
 \begin{tabular}{@{}l@{\hspace{.5em}}l@{\hspace{2em}} r}
 Students: &                    &Professor: \\
 Name1     &\textsc{Surname}    &Name   \textsc{Surname} \\
 Name2     &\textsc{Surname}    &             \\
 Name3     &\textsc{Surname}    &        
 \end{tabular}
 \end{document}

or the version with a full width table and 4 columns

enter image description here

 \documentclass[12pt,a4paper,oneside]{book}
 \usepackage{array,booktabs,siunitx}
 \begin{document}
 \noindent
 \begin{tabular*}{\textwidth}
{@{}
l@{\hspace{.5em}}l
@{\extracolsep{\fill}}
r@{\extracolsep{0pt}\hspace{.5em}}r
@{}}
 \multicolumn{2}{c}{Students:}&
 \multicolumn{2}{c}{Professor:} \\
 Name1     &\textsc{Surname}    &Name&   \textsc{Surname} \\
 Name2     &\textsc{Surname}    &             \\
 Name3     &\textsc{Surname}    &        
 \end{tabular*}
 \end{document}
share|improve this answer
    
Ok, but I would like to have the professor's name completely to the right side of the page, like with \flushright command. And then, I did 4 coloumns for having the same space between names and surnames: with yours commands the space between professor's name en surname is smaller than between the students name... –  Ford Prefect Feb 17 '13 at 11:56
1  
oh currently it the prof name is flush right of the table but the table is not the width of the page. You can make the prof name two columns if you wish but then you need to specify four columns in the table preamble. I'll put a full width table in the answer... –  David Carlisle Feb 17 '13 at 11:58
    
If one inserts >{\scshape} in front of the location specifiers of the 2nd and 4th columns (l and r, respectively) of the tabular or tabular* setup, it won't be necessary to provide the instruction \textsc for the surnames in each and every subsequent row of the table. –  Mico Feb 17 '13 at 13:55
add comment

And then there's the plain TeX halign solution - whenever I see a complex tabular arrangement I can't help thinking how much simpler Knuth's halign is...

\documentclass{article}
\begin{document}

\noindent\halign{#\hfil\ &\textsc{#}\hfil\qquad&\hfil #\cr
\bf Students \span\omit & \bf Professor\cr
Joe & Bloggs & R.J.~\textsc{Drofnats}\cr
Jane & Doe \cr
Eric & Halfbee \cr
Annie & Other \cr
}

\end{document}
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.