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
    \MakeUppercase takes an argument. Compare by replacing \MakeUppercase with \sffamily and \textsf. – Guido Oct 31 '12 at 22:40
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}
| improve this answer | |
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.

| 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

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.