### Who is online

In total there are 12 users online :: 0 registered, 0 hidden and 12 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 12 guests

## Centering the Cell Content in the Table Header

alignmenttablesAdd tags Information and discussion about graphics, figures & tables in LaTeX documents.

### Centering the Cell Content in the Table Header

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:
Code: Select all  •  Open in writeLaTeX
\documentclass[12pt,%%  draft,%  twoside,%  BCOR10mm,%  bib=totoc,        toc=listof,toc=bibliography,numbers=noenddot]{scrreprt}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[spanish,ngerman,catalan,english]{babel}\usepackage{natbib}\usepackage{tabularx}\begin{document}\begin{table}[!ht]\caption{Example}\centering\begin{tabular}{lcclcl}\toprule\textbf{Name} &  \textbf{Surname} &     \textbf{Age} &\textbf{University}& \textbf{Level of Proficiency} \\\midrule Helen & Dooley& 20 & Bern & C2\\ \hline\bottomrule\end{tabular}\label{tab:infogeneralemden}\end{table}\end{document}

Regards,

Marie
marie2011

Posts: 138
Joined: Mon Feb 6th, 2012

### Re: Centering the Cell Content in the Table Header

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.
Code: Select all  •  Open in writeLaTeX
\begin{tabular}{l*{4}{c}}% table content\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.
Code: Select all  •  Open in writeLaTeX
\documentclass[  fontsize=12pt,%  twoside,%  BCOR=10mm,%  bibliography=totoc,  captions=tableabove,  listof=totoc,  numbers=noenddot]{scrreprt}\usepackage[T1]{fontenc}\usepackage[utf8]{inputenc}\usepackage[spanish,ngerman,catalan,english]{babel}\usepackage{array,booktabs}%% Some code from the UK TeX FAQ to influence the style of a complete table row%% see: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=wholerow\newcolumntype{_}{>{\global\let\currentrowstyle\relax}}\newcolumntype{^}{>{\currentrowstyle}}\newcommand{\rowstyle}[1]{%  \gdef\currentrowstyle{#1}%  #1\ignorespaces}\begin{document}  \begin{table}[!ht]    \caption{Example}    \label{tab:infogeneralemden}    \centering    \begin{tabular}{_l*{4}{^c}} \toprule      \rowstyle{\bfseries}      Name & Surname & Age & University & Level of Proficiency \\ \midrule      Helen & Dooley& 20 & Bern & C2 \\ \bottomrule    \end{tabular}  \end{table}\end{document}

Thorsten
LaTeX Community Moderator

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

localghost
Site Moderator

Posts: 9219
Joined: Fri Feb 2nd, 2007
Location: Braunschweig, Germany

### Re: Centering the Cell Content in the Table Header

Hallo Thorsten,

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

Regards,

Marie
marie2011

Posts: 138
Joined: Mon Feb 6th, 2012

alignmenttables