3

For all labels in my drawings I use the common settings

every label/.style = {label distance=1mm, inner sep=0mm,
                  font=\footnotesize\sffamily, align=center,
                  text=teal!60!black},

This works fine as well if labels are in one or more lines until I don't use TikZ library babel. With it in case of one line label in the label node is introduced empty space:

enter image description here

Is this a bug or I miss something in label style definition? How to eliminate this space? Solutions to not use babel or use align=center locally when is needed, for some reason had to leave out of consideration.

The MWE for above picture is:

\documentclass[tikz,border=3mm]{standalone}
   \usetikzlibrary{babel}

\begin{document}
    \begin{tikzpicture}[
every label/.style = {label distance=1mm, inner sep=0mm,
                      font=\footnotesize\sffamily, align=center,
                      text=teal!60!black},
        dot/.style = {circle, fill=black, inner sep=0mm, outer sep=0mm, 
                      minimum size=1mm,
                      node contents={}},
                        ]
%   axes
\draw[->]   (-1.7,0) -- (2.4,0) node[fill=cyan,below left] {$\phi_1(t)$};
\draw[->]   (0,-1.7) -- (0,2.4) node[fill=cyan,below left] {$\phi_2(t)$};
    \draw[densely dashed,very thin] (0,0) circle (13mm);
%   signals
\foreach \i [count=\ix from 1] in {0,90,180,270}
\draw   (\i:13mm) node[dot,label={[fill=yellow]\i+45:$s_{\ix}$}];
%----------------
    \end{tikzpicture}
\end{document}
Zarko
  • 296,517
  • Probably somewhere in the code there is a un%terminated line somewhere. However this works without space \draw (\i:13mm) node[dot,label={[fill=yellow,node contents={$s_\ix$}]\i+45:}];. In case you run out of options :) – percusse May 30 '16 at 08:15
  • Yes, this works,but with this I need to change more than hundreds illustrations :-(. I notice reported misbehavior when i had to introduce babel due to problem with quotes library and slovene babel. – Zarko May 30 '16 at 08:24

1 Answers1

3

The library activates the option handle active characters in nodes and this uses \scantokens to process the contents of the nodes with different catcodes. \scantokens (like \input) inserts a space at the end. You can suppress it with some command at the end which will eat following spaces, e.g. \ignorespaces or a simple \relax:

\documentclass[tikz,border=3mm]{standalone}
   \usetikzlibrary{babel}

\begin{document}
    \begin{tikzpicture}[
every label/.style = {label distance=1mm, inner sep=0mm,
                      font=\footnotesize\sffamily, align=center,
                      text=teal!60!black},
        dot/.style = {circle, fill=black, inner sep=0mm, outer sep=0mm,
                      minimum size=1mm,
                      node contents={}},
                        ]
%   axes
\draw[->]   (-1.7,0) -- (2.4,0) node[fill=cyan,below left] {$\phi_1(t)$};
\draw[->]   (0,-1.7) -- (0,2.4) node[fill=cyan,below left] {$\phi_2(t)$};
    \draw[densely dashed,very thin] (0,0) circle (13mm);
%   signals
\foreach \i [count=\ix from 1] in {0,90,180,270}
\draw   (\i:13mm) node[dot,label={[fill=yellow]\i+45:$s_{\ix}$\relax}];
%----------------
    \end{tikzpicture}
\end{document}

enter image description here

Edit

Actually I think it is a bug. pgf should hide the end-of-file marker when using \scantokens. This here corrects the problem in your case (there are other places where \scantoken is used, so it could pop up again):

\documentclass[tikz,border=3mm]{standalone}
   \usetikzlibrary{babel}
\makeatletter

\def\tikz@@parse@label@nonactive[#1]#2:#3:\pgf@nil{%
  \tikzset{%
    append after command = {%
      \bgroup
        [current point is local=true]
        \pgfextra{\let\tikz@save@last@fig@name=\tikz@last@fig@name\tikz@node@is@a@labelfalse}
        node [every label,
              tikz@label@angle = #2,
              anchor=@auto,
              #1,
              tikz@label@post = \tikz@label@distance] {\iftikz@handle@active@nodes\expandafter\scantokens\else\expandafter\pgfutil@firstofone\fi{#3\noexpand}}
        \pgfextra{\global\let\tikz@last@fig@name=\tikz@save@last@fig@name}
      \egroup}}}

\makeatother      
\begin{document}
    \begin{tikzpicture}[
every label/.style = {label distance=1mm, inner sep=0mm,
                      font=\footnotesize\sffamily, align=center,
                      text=teal!60!black,
                      fill=yellow,
                      },
        dot/.style = {circle, fill=black, inner sep=0mm, outer sep=0mm,
                      minimum size=1mm,
                      node contents={}},
                        ]
%   axes
\draw[->]   (-1.7,0) -- (2.4,0) node[fill=cyan,below left] {$\phi_1(t)$};
\draw[->]   (0,-1.7) -- (0,2.4) node[fill=cyan,below left] {$\phi_2(t)$};
    \draw[densely dashed,very thin] (0,0) circle (13mm);
%   signals
\foreach \i [count=\ix from 1] in {0,90,180,270}
\draw   (\i:13mm) node[dot,label={[fill=yellow]\i+45:$s_{\ix}$}];
%----------------
    \end{tikzpicture}
\end{document}

See https://tex.stackexchange.com/a/9829/2388 for a discussion about the \noexpand.

Ulrike Fischer
  • 327,261