11

This question already has an answer here:

(I am a new to LaTeX.) I'm trying to print a length in centimeters. Here is my code:

\documentclass{article}
\begin{document}
\newdimen\mylength
\mylength=1in 
\the\mylength
\end{document}

And here is the resulting output:

72.27 pt

However, I want to show output in centimeters: Example: \the dimen [cm]\mylength. How can I do that?

marked as duplicate by jub0bs, Werner, DG', Svend Tveskæg, egreg xetex Apr 19 '15 at 19:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

8

You can use the \convertto macro from Philippe Goutet's post:

\documentclass{article}

\makeatletter
\def\convertto#1#2{\strip@pt\dimexpr #2*65536/\number\dimexpr 1#1}
\makeatother

\begin{document}
\newdimen\mylength
\mylength=1in
\convertto{cm}{\the\mylength} cm
\end{document}

Output:

2.54cm

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