GeneralDifferent format for different cells in tabular

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
Longinus
Posts: 7
Joined: Mon Nov 03, 2008 7:13 pm

Different format for different cells in tabular

Post by Longinus »

Dear all, nice to meet you.

This is my first post and I have some question that I cannot figure out in tabular after some search on the Internet and reference to the article by Mori.

I am going make a table like this:

Code: Select all

\documentclass{report}
\usepackage{booktabs, tabularx, multirow, array}
\setlength{\heavyrulewidth}{0.1em}
\newcommand{\otoprule}{\midrule[\heavyrulewidth]}

\begin{document}

\begin{table}[hb]
	\centering
	\caption{Table description here\\}%
		\begin{tabular}{l c c c}\toprule%
			Division & Total cases &  Population  &	    Annual rate     \\%
			         & (1991--2004)& $\geq$ 65 yo & (/1,000,000 elderly)\\\otoprule%
      New England           &1639  &1891629   &61.89\\
      Middle Atlantic       &4307  &5480653   &56.13\\\bottomrule%
    \end{tabular}
\end{table}

\end{document}
I'd like to have the top column title bold and centered, and all the numbers in the 2nd row and on aligned to the right. Is there any quick and/or correct way to do this other than assigning all of them in their own \makebox statement?

Thank you very much for your time and help.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Different format for different cells in tabular

Post by Stefan Kottwitz »

Hi Longinus,

you could make the general settings in the table parameters and use \multicolumn to set the format in the cells of the first row, like \multicolumn{1}{c}{text} while using r columns.

Stefan
LaTeX.org admin
Longinus
Posts: 7
Joined: Mon Nov 03, 2008 7:13 pm

Different format for different cells in tabular

Post by Longinus »

Thanks Stefan,

I did it! It seems to work fine:

Code: Select all

\documentclass{report}
\usepackage{booktabs, tabularx, multirow, array}
\setlength{\heavyrulewidth}{0.1em}
\newcommand{\otoprule}{\midrule[\heavyrulewidth]}

\begin{document}

\begin{table}[hb]
   \centering
   \caption{Table description here\\}%
      \begin{tabular}{l r r r}\toprule%
         \multicolumn{1}{c}{\bfseries{Division}} &
         \multicolumn{1}{c}{\bfseries{Total cases}} &  
         \multicolumn{1}{c}{\bfseries{Population}}  &       
         \multicolumn{1}{c}{\bfseries{Annual rate}}     \\%
                  & 
         \multicolumn{1}{c}{\bfseries{(1991--2004)}}&
         \multicolumn{1}{c}{\bfseries{$\geq$ 65 yo}} &
         \multicolumn{1}{c}{\bfseries{(/1,000,000 elderly)}}\\\otoprule%
      New England           &1639  &1891629   &61.89\\
      Middle Atlantic       &4307  &5480653   &56.13\\\bottomrule%
    \end{tabular}
\end{table}

\end{document}
Thank you so much!!
Post Reply