26

I would like to suppress the space before the colon, when using [french]babel. I only want to change this locally (that is not everywhere in the document, but just at some place).

\documentclass{article}
\usepackage[french]{babel}

\begin{document}
Il est 20:20.
\end{document}

enter image description here

Colas
  • 6,772
  • 4
  • 46
  • 96

3 Answers3

30

Your problem is with the Babel shorthand for :. To disable this shorthand use \shorthandoff{:} inside your \begin{document}. It will not work when loaded in the preamble.

To re-enable the shorthand, use \shorthandon{:}.

\documentclass{article}
\usepackage[french]{babel}

\begin{document}
\shorthandoff{:}
Il est 20:20.

\shorthandon{:}
Il est 20:20.
\end{document}

enter image description here

Herthog
  • 928
15

I'm not sure this is the usual way to denote time in French; here's a workaround:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}

\edef\hc{\string:} % \hc prints a normal colon

\begin{document}
Il est 20\hc20.
\end{document}

Alternatively, use datetime:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[french]{babel}
\usepackage{datetime}

\newcommand\heure[2]{\formattime{#1}{#2}{00}}

\begin{document}
Il est \heure{20}{20}
\end{document}

enter image description here

egreg
  • 1,121,712
14

As suggested by PatrickT and mentioned in French internationalisation, override babel default spacing, \NoAutoSpacing is the easiest solution in modern (post-2011) TeX distributions.

\documentclass{article}
\usepackage[french]{babel}

\begin{document}
Il est {\NoAutoSpacing 20:20}.
\end{document}
  • Could you please add a MWE? – Colas Aug 12 '16 at 10:43
  • edit: added a MWE – Frédéric Devernay Sep 06 '17 at 07:17
  • See also the documentation of Babel French http://daniel.flipo.free.fr/frenchb/frenchb-doc.pdf This command is necessary for example for natbib bibliography style plainnat (and \shorthandoff does not work in that case). – yannis Sep 22 '18 at 13:54
  • Thanks for writing this up, because I had forgotten about my comment of 8 years ago. This issue came up again with the package datetime. To get the correct spacing, I've had to type \NoAutoSpacing\currenttime to get the correct spacing when compiling with XeLaTex. I wish I could upvote again! – PatrickT Jan 14 '24 at 07:14