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 need one column of my table to be uppercased. My code which does not work as I want:

\documentclass{article}

\usepackage{array}

\begin{document}

\begin{tabular}{c>{\MakeUppercase}c}
    a & b
\end{tabular}

\end{document}

What's the problem?

share|improve this question
1  
\MakeUppercase takes an argument. Compare by replacing \MakeUppercase with \sffamily and \textsf. –  Guido Oct 31 '12 at 22:40

2 Answers 2

up vote 14 down vote accepted

Our own Martin Scharrer's collcell package is ideal for this sort of thing:

\documentclass{article}

\usepackage{array}
\usepackage{collcell}
\newcolumntype{U}{>{\collectcell\MakeUppercase}c<{\endcollectcell}}
\begin{document}

\begin{tabular}{cU}
    a & b
\end{tabular}

\end{document}
share|improve this answer

If you use a macro like \MakeUpperCase with no {} then it will take the first token following as argument but in this case that token is not b but:

\MakeUppercase #1->\protect \MakeUppercase  {#1}
#1<-\ignorespaces 

the \ignorespaces token that LaTeX places at the front of each cell so that white space after & is ignored.

share|improve this answer
    
Very nice complement to Alan's solution, responding to the "What's the problem?" question. –  doncherry Nov 1 '12 at 7:16

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.