2

I want a horizontal length to have the same length as the word "physique".

This is what I have tried:

\documentclass{article}

\usepackage[latin1]{inputenc} 
\usepackage[T1]{fontenc} 
\usepackage[francais]{babel}

\newlength{\longueurperso}
\setlength{\longueurperso}{30pt}

\newlength{\motphysique}
\settolength{\motphysique}{physique}

\begin{document}
Bonjour! 

Voici un espace horizontal de \hspace{\longueurperso} 30 points. 

La \hspace{\motphysique} est une science pure.
\end{document}

When I compile, here is what I get:

enter image description here

What's wrong? I tried to put the lines

\newlength{\motphysique}
\settolength{\motphysique}{physique}

after the \begin{document} and it's not working better.

5

\setlength expects lengths to be given explicitly like 30pt. You have two options. First use \settowidth as mentioned by Yiannis Lazarides: \settowidth{\motphysique}{physique}. Second, if you want to stick with \setlength, load calc package and define \setlength{\motphysique}{\widthof{physique}}.

\documentclass{article}

\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[francais]{babel}
\usepackage{calc}    %% provides \widthof
\newlength{\longueurperso}
\setlength{\longueurperso}{30pt}

\newlength{\motphysique}
%\settowidth{\motphysique}{physique}
\setlength{\motphysique}{\widthof{physique}}

\begin{document}
Bonjour!

Voici un espace horizontal de \hspace{\longueurperso} 30 points.

La \hspace{\motphysique} est une science pure.
\end{document}

enter image description here

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.