I'm using the pbox package's \settominwidth command to measure the typeset width of text that includes explicit line breaks (which is a case in which standard LaTeX's settowidth doesn't work).

In the following MWE, I add a brace group to localize the effect of a color switch (\color{red}). Adding the brace group causes an error when that command is passed to \settominwidth: Missing } inserted.

I'd like to know what's illegitimate about adding the brace group. (Note that the color switch without the added brace group, in \textA, doesn't raise a complaint.)

I'm also curious why \settominwidth reports about 2pt more width for \widthB than for \widthA, but that's not a mandatory part of the solution.

I realize that, in this limited MWE, I could avoid the issue by using \textcolor{red}{someText} instead, but this MWE is abstracted from a larger context in which a switch is preferable.

Stack Exchange suggested as a "similar question": "Why can't I use braces in an \if… \fi group?". Perhaps it holds the key, but I don't know enough about \settominwidth to know.

\newcommand{\textA}{\color{blue} One \\ Two}
\newcommand{\textB}{{\color{red} One \\ Two}}


\texttt{\textbackslash{}widthA}: \the\widthA\\
\texttt{\textbackslash{}widthB}: \the\widthB



After text

enter image description here


\settominwidth uses internally a tabular. This means that you are doing

{\color{red} One \\ Two}

And this doesn't work as cell are groups.

  • what would be the general formulation of what you can't do in the argument of \settominwidth? Is it just that you can't encapsulate the entire argument in a brace group? Or is it more general than that? – Jim Ratliff Dec 23 '18 at 20:30

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.