# Problem with lengths

I'm trying to insert some space between the label and the form control in hyperref forms. The following example works:

\documentclass{scrartcl}

\usepackage{calc}
\usepackage{hyperref}

\newcommand\insertlabel[1]{%
% \newlength\twidth
% \setlength\twidth{10em-\widthof{#1}}}
#1:\hspace{4em}
}

\begin{document}
\begin{Form}
\TextField{\raisebox{.9ex}{\insertlabel{Name}}}
\end{Form}
\end{document


But the following doesn't work:

\documentclass{scrartcl}

\usepackage{calc}
\usepackage{hyperref}

\newcommand\insertlabel[1]{%
\newlength\twidth
\setlength\twidth{10em}
#1:\hspace{\twidth-\widthof{#1}}
}

\begin{document}
\setlength\parindent{0pt}
\begin{Form}
\TextField{\raisebox{.9ex}{\insertlabel{Name}}} \\
\end{Form}
\end{document}


Can somebody please tell me what the problem is?

• Do you want to rephrase your title to "problem with lengths"? or something simmilar? I suppose it will help more people like this. PS: Thanks for accepting and upvoting :) – koleygr Oct 31 '17 at 1:02

Just remove the newlength from the newcommand and place it over it.

\documentclass{scrartcl}

\usepackage{calc}
\usepackage{hyperref}
\newlength{\twidth}
\newcommand\insertlabel[1]{%
\setlength\twidth{10em-\widthof{#1}}
#1:\hspace{\twidth}
}

\begin{document}
\setlength\parindent{0pt}
\begin{Form}
\TextField{\raisebox{.9ex}{\insertlabel{Name}}}
\end{Form}
\end{document}


\newlength command has to be given in preamble... and your command call it from inside the document.

Also, hspace needs a lenght as an argument and not calculations of a length. Calculated before used here.

Finally I removed the \\ that creates unnecessary underfull hbox