3

I want to set the \extrarowheight to 0.5ex. I find the following three ways are all applicable.

\extrarowheight = 0.5ex
\setlength{\extrarowheight}{0.5ex}
\renewcommand{\extrarowheight}{0.5ex}

Just out of curiosity, which way is the canonical one?

  • One is setting it the tex way, one is using the latex way, one is more or less just wrong. – Johannes_B Dec 11 '18 at 6:13
  • @Johannes_B I beg to differ. \arraystretch can only be changed by \renewcommand since \arraystretch is implemented as a macro rather than a variable. – Eli4ph Dec 13 '18 at 11:04
7

As mentioned in the comments, the first version is the TeX version of assignments, the second version is the LaTeX version of assigning values to variables. Both usually yield the same result, as the second one is based on the first.

The second version is less error-prone, though, because it's equivalent to \extrarowheight=0.5ex\relax which prevents the parser from accidentally mistaking extra characters after the assignment to be part of the new value.

Note however, that the third version is not equivalent to the other two, and wrong in that sense. It doesn't do a variable assignment but redefines \extrarowheight to be a macro which expands to the token sequence 0.5ex. You can see the difference when you try the following:

\setlength{\extrarowheight}{0.5ex}
\show\extrarowheight

outputs

\extrarowheight=\dimen104.

while

\renewcommand{\extrarowheight}{0.5ex}
\show\extrarowheight

outputs

\extrarowheight=\long macro:
->0.5ex.

In some cases the use of that macro will still yield the same result as the use of the variable, but as soon as you try to set the variable the correct way, the problem becomes apparent:

\renewcommand{\extrarowheight}{0.5ex}
\setlength{\extrarowheight}{1.0ex}

prints 0.5ex1.0ex instead of doing an assignment.

  • 1
    Good answer. Note that \setlength and others can be extended by package like calc to handle simple equations, e.g. \setlength{\somelength}{\baselineskip + .5ex}. Then it is not equivialent to the TeX assignment anymore. – Martin Scharrer Dec 11 '18 at 7:29
  • Thanks for the detailed description. By the way, is \extrarowheight 0.5ex also legitimate? – Eli4ph Dec 13 '18 at 9:07
  • Note that standard LaTeX \arraystretch is implemented as a macro. Thus it is not a variable and the "conceptual" assignment to it can only be achieved by \renewcommand. Actually, this is the origin for my question – people use \renewcommand for \arraystretch while \setlength for \extrarowheight. – Eli4ph Dec 13 '18 at 11:00
  • 1
    @eli People use different things because things are implemented differently. You cannot use everyting everywhere. So the simple answer would be: use the right tool for the job. Not everything can be fixed by whacking it with a hammer. – Johannes_B Dec 13 '18 at 11:10
  • @Johannes Agree! The motivation for this question is to do things right. Apparently I did not realize the difference between \arraystretch and \extrarowheight when asking this question. – Eli4ph Dec 13 '18 at 11:15

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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