4

When I use factors of a variable in tabu's cell description, the result is not what I intended. For example in the following code, the middle cell is not half the width of the others.

\documentclass{article}
\usepackage[english]{babel}
\usepackage{tabu}

\newcommand \myWidth {60mm}

\begin{document}
    \begin{tabu}
    {|p{\myWidth}| p{.5\myWidth}|p{\myWidth}|}a & b & c
    \end{tabu}  
\end{document}

results in

Result

1 Answer 1

7

You need a length register:

\documentclass{article}
\usepackage[english]{babel}
\usepackage{tabu}

\newlength \myWidth
\setlength\myWidth {60mm}

\begin{document}
    \begin{tabu}
    {|p{\myWidth}| p{.5\myWidth}|p{\myWidth}|}a & b & c
    \end{tabu}  
\end{document}

Your original would just work by macro expansion so

p{.5\myWidth}

would be the same as

p{.560mm}

which is legal, but smaller than you intended.

2
  • Or .5\dimexpr\myWidth\relax
    – egreg
    Apr 12, 2013 at 13:02
  • @egreg yes or perhaps less intrusive \newcommand \myWidth {\dimexpr60mm\relax} But a length register is simpler now e-tex has lots of them. Apr 12, 2013 at 13:04

You must log in to answer this question.

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