LaTeX forum ⇒ Graphics, Figures & TablesCentering the Cell Content in the Table Header Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
marie2011
Posts: 138
Joined: Mon Feb 06, 2012 4:58 pm

Centering the Cell Content in the Table Header

Postby marie2011 » Sat Dec 08, 2012 12:23 am

Dear forum members,

I was wondering how I can center just specific contents of a heading in a table. I would like to center the word "University" and "Bern".

I have a minimal example:
  1. \documentclass[
  2. 12pt,%
  3. % draft,%
  4. twoside,%
  5. BCOR10mm,%
  6. bib=totoc,
  7. toc=listof,
  8. toc=bibliography,
  9. numbers=noenddot
  10. ]{scrreprt}
  11.  
  12. \usepackage[T1]{fontenc}
  13. \usepackage[utf8]{inputenc}
  14. \usepackage[spanish,ngerman,catalan,english]{babel}
  15. \usepackage{natbib}
  16. \usepackage{tabularx}
  17.  
  18. \begin{document}
  19. \begin{table}[!ht]
  20. \caption{Example}
  21. \centering
  22. \begin{tabular}{lcclcl}
  23. \toprule
  24. \textbf{Name} & \textbf{Surname} & \textbf{Age} &
  25. \textbf{University}& \textbf{Level of Proficiency} \\
  26. \midrule
  27. Helen & Dooley& 20 & Bern & C2\\
  28. \hline
  29. \bottomrule
  30. \end{tabular}
  31. \label{tab:infogeneralemden}
  32. \end{table}
  33. \end{document}


Many thanks in advance.

Regards,

Marie

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
localghost
Site Moderator
Posts: 9206
Joined: Fri Feb 02, 2007 12:06 pm
Location: Braunschweig, Germany

Postby localghost » Sat Dec 08, 2012 10:49 am

Please check your examples for functionality and minimal content before you add them to a question. In your example here at least the booktabs package is missing to get the table. And the packages natbib and tabularx are not needed here to reproduce the problem.

You want nothing else then centering the content of a whole column. So you did a small mistake in the table preamble. You declare six columns but you use only five. Furthermore there is an l column type where you do not want it. Your table preamble should read like this.
  1. \begin{tabular}{l*{4}{c}}
  2. % table content
  3. \end{tabular}

This will center all columns except for the first one. I don't know if that is what you want but you should be able to correct this if necessary.

Since you want your table header to be in bold type face, it is suggestive to incorporate some code from the UK TeX FAQ (see code below). It requires to load the array package for the declaration of some new column types.
  1. \documentclass[
  2. fontsize=12pt,%
  3. twoside,%
  4. BCOR=10mm,%
  5. bibliography=totoc,
  6. captions=tableabove,
  7. listof=totoc,
  8. numbers=noenddot
  9. ]{scrreprt}
  10. \usepackage[T1]{fontenc}
  11. \usepackage[utf8]{inputenc}
  12. \usepackage[spanish,ngerman,catalan,english]{babel}
  13. \usepackage{array,booktabs}
  14.  
  15. %% Some code from the UK TeX FAQ to influence the style of a complete table row
  16. %% see: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wholerow
  17. \newcolumntype{_}{>{\global\let\currentrowstyle\relax}}
  18. \newcolumntype{^}{>{\currentrowstyle}}
  19. \newcommand{\rowstyle}[1]{%
  20. \gdef\currentrowstyle{#1}%
  21. #1\ignorespaces
  22. }
  23.  
  24. \begin{document}
  25. \begin{table}[!ht]
  26. \caption{Example}
  27. \label{tab:infogeneralemden}
  28. \centering
  29. \begin{tabular}{_l*{4}{^c}} \toprule
  30. \rowstyle{\bfseries}
  31. Name & Surname & Age & University & Level of Proficiency \\ \midrule
  32. Helen & Dooley& 20 & Bern & C2 \\ \bottomrule
  33. \end{tabular}
  34. \end{table}
  35. \end{document}



Thorsten
LaTeX Community Moderator
How to make a "Minimal Example"
Board Rules
Avoidable Mistakes


¹ System: openSUSE 13.1 (Linux 3.11.10), TeX Live 2013 (vanilla), TeXworks 0.5 (r1351)
² Posting stopped indefinitely due to offenses

Link:
BBcode: Topic is solved[/url]" title="Click to select post's link in BBcode format" onclick="this.focus();this.select();" />
HTML: Topic is solved</a>" title="Click to select post's link in HTML format" onclick="this.focus();this.select();" />
Hide post links
Show post links

marie2011
Posts: 138
Joined: Mon Feb 06, 2012 4:58 pm

Postby marie2011 » Sat Dec 08, 2012 11:12 am

Hallo Thorsten,

Many thanks for your prompt answer. I am going to try what you suggested.

Regards,

Marie

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Google [Bot] and 2 guests