Graphics, Figures & TablesMake heading row of table bold

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
User avatar
Steztric
Posts: 12
Joined: Sat Oct 25, 2008 2:00 pm

Make heading row of table bold

Post by Steztric »

Hi everybody,

This must seem like a very simple question, but I want to make the heading row of a table bold. Unfortunately I can't find any tutorials anywhere that tells me how to do this? I can make an entire column bold by going

Code: Select all

\begin{tabular}{>{\bfseries}l}
But this code doesn't help for rows...

Thanks,

Steve
I can do magic too... Pass me that muffin. Now you see it; now woo down'.

Recommended reading 2024:

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

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Make heading row of table bold

Post by gmedina »

Hi,

you could use \textbf for each entry:

Code: Select all

\documentclass{article}

\begin{document}

\begin{tabular}{ccc}\hline
  \textbf{First column} & \textbf{Second column} & \textbf{Third column}\\ \hline
  text1a & text2a & text3a\\
  text1b & text2b & text3b 
\end{tabular}

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
Steztric
Posts: 12
Joined: Sat Oct 25, 2008 2:00 pm

Make heading row of table bold

Post by Steztric »

Thanks, that's true. It is an awkward hack though. Some tables I have are rotated and have 15 columns. This makes for a lot of \textbf'ing (not that text would be inclined to do so...). Surely there is a more elegant way of making an entire row bold?
I can do magic too... Pass me that muffin. Now you see it; now woo down'.
User avatar
Steztric
Posts: 12
Joined: Sat Oct 25, 2008 2:00 pm

Make heading row of table bold

Post by Steztric »

Hi guys.

I managed to solve the problem. I found some documentation on the matter. It requires a couple of new definitions and some tokens in the table column definitions to get it done, but it's possible;

Code: Select all

\newcolumntype{+}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}

\begin{table}[htb]
\centering
\begin{tabular}{+l^l^l}
\rowstyle{\bfseries}%
Column & Text & Description\\
\hline
1      & Itn  & Iteration number\\
2      & AveC & Average cost across all genomes in population\\
3      & AveF & Average fitness of all genomes\\
4      & MinC & The lowest cost from any genome (ignoring overfill)\\
5      & MinF & The fittest gene in the current population\\
6      & BGP  & Best Genome Position in population\\
\end{tabular}
\caption{Statistics File Columns Description}
\label{tab:statsform}
\end{table}
So the short&simple of it is, copy the \newcolumntype commands into your code. Wherever you need to format an entire row, you need to add the + and ^ tokens to your row definitions and then include the \rowstyle to choose how you want the row to be formatted.

Good luck,

Steve
I can do magic too... Pass me that muffin. Now you see it; now woo down'.
thuldai
Posts: 2
Joined: Thu Dec 18, 2008 3:52 pm

Re: Make heading row of table bold

Post by thuldai »

That seems messy indeed. And with me it doesn't work, I'm getting:

! Undefined control sequence.
l.516 \newcolumntype
{^}{>{\currentrowstyle}}

I tried putting those commands before my \begin{document} and after - both times with the same error (except for the line number). And as I don't really understand what's going on, I'm clueless as to try what next.

Using pdflatex, maybe that has sth to do with it?

Thanks for any hints.

Might just do the \textbf{} crutch, although it IS embarrassingly inelegant.

EDIT:
Also wanted to point you that I'm trying to use this in a rotated table (sidewaystable environment).

And one more question:
Could you be a bit more specific on where to put those +'s and ^'s? In particular I have a tabular like this:
\begin{tabular}{l|rrr|rrr|rrr|rrr|}
And I'm clueless as to where (for example in relation to the |'s) to put them and how many.

Ah, guess that's all a bit too advanced to me... :oops:
phi
Posts: 577
Joined: Tue Oct 21, 2008 8:10 pm

Make heading row of table bold

Post by phi »

thuldai wrote:That seems messy indeed.
Why? It's probably as elegant as you can get with simple LaTeX.
thuldai wrote:And with me it doesn't work
You need to include the array package
thuldai
Posts: 2
Joined: Thu Dec 18, 2008 3:52 pm

Make heading row of table bold

Post by thuldai »

Thanks that helped. For other noobs (like me), here some filling-in of blanks:

Before your \begin{document}, put this (or something like it):

Code: Select all

\usepackage{array}
\newcolumntype{+}{>{\global\let\currentrowstyle\relax}}
\newcolumntype{^}{>{\currentrowstyle}}
\newcommand{\rowstyle}[1]{\gdef\currentrowstyle{#1}%
#1\ignorespaces
}
Then if you had something like this:

Code: Select all

\begin{tabular}{l|rrr|rrr|rrr|rrr|}
you have to turn it into this

Code: Select all

\begin{tabular}{+l|^r^r^r|^r^r^r|^r^r^r|^r^r^r|}
i.e. the ^'s are always AFTER a potential vertical line.

Then it worked smoothly, even with a rotated table.

Enjoy!

And thanks for the help.
Post Reply