I'd like to pass a measure of length in form of a string, i.e.




instead of


I seem to remember seeing something like that somewhere in LaTeX, but can't find it. Appreciate your input!

  • 4
    Are you looking for \settowidth{\somelength}{string}?
    – egreg
    Jan 27, 2016 at 22:23
  • 6
    Possible duplicate: Get width of a given text as length
    – Werner
    Jan 27, 2016 at 22:25
  • 1 minute. I love StackExchange. @egreg Wonderful, thanks a lot! I'd mark it as the answer, but I can't do that with a comment. Werner - it's not the exact same issue, though I see your point.
    – Zubo
    Jan 27, 2016 at 22:28
  • @Zubo: Questions are phrased differently, but they use the same principles. The other is actually a little more comprehensive than this request, making this one a subset of the linked post (in my opinion). I'm voting to close as a duplicate.
    – Werner
    Jan 27, 2016 at 23:41

1 Answer 1


The LaTeX kernel provides


and you probably want the first one:


\settowidth{\somelength}{some text}

Note that it's better to set lengths to a text dependent width after \begin{document}. So, if you need \somelength for a macro definition in the preamble, you should do

\newcommand{\foo}{...depending on \somelenght...}

\AtBeginDocument{\settowidth{\somelength}{some text}}
  • Excellent, thanks for the detailed explanation!
    – Zubo
    Jan 27, 2016 at 22:58

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