12

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?

1
  • 1
    \MakeUppercase takes an argument. Compare by replacing \MakeUppercase with \sffamily and \textsf.
    – Guido
    Oct 31, 2012 at 22:40

2 Answers 2

14

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}
9

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.

1
  • Very nice complement to Alan's solution, responding to the "What's the problem?" question.
    – doncherry
    Nov 1, 2012 at 7:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .