5

I would like to pass colors as argument to the pic command \pic at (-4,0) {bubblelab={label=A,color=orange, fill=orange length=0.8, scale=0.8}};but i've got undefined color error. Do you have any idea how to do so?

enter image description here

main.tex

%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}


%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz}%  permet de dessiner des figures, des graphiques
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre

%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)

%%%%%%%%%%%%%%%%%% COLORS %%%%%%%%%%%%%%%%%%
\definecolor{orange}{RGB}{245,128,37}
\definecolor{bleu}{RGB}{0,0,255}
\definecolor{gris}{RGB}{158,158,158}
\definecolor{vert}{RGB}{0,178,0}
\definecolor{rouge}{RGB}{255,0,0}
\definecolor{violet}{RGB}{190,0,120}

%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\input{types/f2d_label}

\tikzset{pictparam/.style={font={\sansmath\sffamily}, thick, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm, scale=1}}

%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{adjustbox}{width={15cm},totalheight={15cm},keepaspectratio}
\begin{tikzpicture}[pictparam, scale=0.1]
    %\pic {droitegrad={min=-20, max=80, secondsgrad=-18, secondbgrad=-10, firstlab=-10, secondlab=0, lastlab=20, dscale=20}};
    %\pic {bubblelab={label=A, point=-4, scale=0.8}};
    \draw[->] (-20,0) -- (5+80,0);
    \foreach \x in {-20,-18,...,80}
    {   \draw[shift={(\x,0)},color=black] (0pt,20pt) -- (0pt,-20pt);
    }
    \foreach \x in {-20,-10,...,80}
    {   \draw[shift={(\x,0)},color=black] (0pt,45pt) -- (0pt,-45pt);
    }
    \foreach \x in {-10,0,...,20}
    {   \draw[shift={(\x,0)},color=black] (0,0) node[inner sep=10pt, below, scale=0.9] {\x};
    }
    %\draw[color=orange, ->] (-4,2) -- ++(0,8) node[fill=orange!20, anchor=south, scale=0.8, circle] {A};
    \pic at (-4,0) {bubblelab={label=A,color=orange, fill=orange length=0.8, scale=0.8}};
    \draw[color=orange, ->] (4,2) -- (4,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {B};
    \draw[color=orange, ->] (14,2) -- (14,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {C};
    \draw[color=orange, ->] (28,2) -- (28,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {D};
    \draw[color=orange, ->] (52,2) -- (52,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {E};
    \draw[color=orange, ->] (72,2) -- (72,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {F};
\end{tikzpicture}
\end{adjustbox}
\end{document}

f2d_label.tex

%%%%%%%%%%%%%%%%%%%%%%%% bblarrow %%%%%%%%%%%%%%%%%%%%%%%%
% Example:
% \pic[fill=green, text=green, draw=black, opacity=.7] at (5,0) {bubblelab={label=3, color=3, length=2, scale=1}};
%
%%  Labelle à bulle
\tikzset{
    pics/bubblelab/.style={
        code={
            \tikzset{bubblelab/.cd,#1}
            \def\pv##1{
                \pgfkeysvalueof{/tikz/bubblelab/##1}
            }
        \draw[color=\pv{color}, ->] (0,0.2) -- ++(0,\pv{length}) 
        node[color=\pv{color},fill=\pv{fill}!20, anchor=south, scale=\pv{scale}, circle] {\pv{label}};;
    }
    },
    bubblelab/.cd,
    label/.initial=A,
    color/.initial=black,
    fill/.initial=black,
    length/.initial=0.8,
    scale/.initial=0.8,
}

I looked on internet and stackexchange, but didn't find anything to help :/

Have a nice day!

7

You need to be a bit more careful with spaces. Change your file f2d_label.tex to become

%%%%%%%%%%%%%%%%%%%%%%%% bblarrow %%%%%%%%%%%%%%%%%%%%%%%%
% Example:
% \pic[fill=green, text=green, draw=black, opacity=.7] at (5,0) {bubblelab={label=3, color=3, length=2, scale=1}};
%
%%  Labelle à bulle
\tikzset{
    pics/bubblelab/.style={
        code={
            \tikzset{bubblelab/.cd,#1}
            \def\pv##1{% <- added
                \pgfkeysvalueof{/tikz/bubblelab/##1}% <- added
            }
        \draw[color=\pv{color}, ->] (0,0.2) -- ++(0,\pv{length}) 
        node[color=\pv{color},fill=\pv{fill}!20, anchor=south, scale=\pv{scale}, circle] {\pv{label}};;
    }
    },
    bubblelab/.cd,
    label/.initial=A,
    color/.initial=black,
    fill/.initial=black,
    length/.initial=0.8,
    scale/.initial=0.8,
}

where the changes are marked by <- added. (If you were to use the /.expanded key as in \draw[color/.expanded=\pv{color},..., some of the spaces would get removed automatically.)

Also, in your main file, a comma is missing in

\pic at (-4,0) {bubblelab={label=A,color=orange, fill=orange length=0.8, scale=0.8}};

which needs to become

 \pic at (-4,0) {bubblelab={label=A,color=orange, fill=orange,length=0.8, scale=0.8}};

with a comma after orange. (Note that I removed types/ in \input{types/f2d_label} because I did not want to create a subfolder in the folder I am working.)

%%%%%%%%%%%%%%%%%% INTRODUCTION %%%%%%%%%%%%%%%%%%
\documentclass[border=10pt]{standalone}


%%%%%%%%%%%%%%%%%% PACKAGE %%%%%%%%%%%%%%%%%%
\usepackage{tikz}%  permet de dessiner des figures, des graphiques
\usepackage{adjustbox}% permet de déterminer une taille de fenêtre

%%  FONT
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tgadventor}% paquet de police de caractère TGadventor
\usepackage{sansmath}%  Copie-colle la police active dans \sfdefault (/!\ N'EST PAS UNE POLICE DE CARACTÈRES)

%%%%%%%%%%%%%%%%%% COLORS %%%%%%%%%%%%%%%%%%
\definecolor{orange}{RGB}{245,128,37}
\definecolor{bleu}{RGB}{0,0,255}
\definecolor{gris}{RGB}{158,158,158}
\definecolor{vert}{RGB}{0,178,0}
\definecolor{rouge}{RGB}{255,0,0}
\definecolor{violet}{RGB}{190,0,120}

%%%%%%%%%%%%%%%%%% SETUP %%%%%%%%%%%%%%%%%%
\input{f2d_label} % \input{types/f2d_label}

\tikzset{pictparam/.style={font={\sansmath\sffamily}, thick, line cap=round, line join=round, >=latex, x=1.0cm, y=1.0cm, scale=1}}

%%%%%%%%%%%%%%%%%% DOCUMENT %%%%%%%%%%%%%%%%%%
\begin{document}
\begin{adjustbox}{width={15cm},totalheight={15cm},keepaspectratio}
\begin{tikzpicture}[pictparam, scale=0.1]
    %\pic {droitegrad={min=-20, max=80, secondsgrad=-18, secondbgrad=-10, firstlab=-10, secondlab=0, lastlab=20, dscale=20}};
    %\pic {bubblelab={label=A, point=-4, scale=0.8}};
    \draw[->] (-20,0) -- (5+80,0);
    \foreach \x in {-20,-18,...,80}
    {   \draw[shift={(\x,0)},color=black] (0pt,20pt) -- (0pt,-20pt);
    }
    \foreach \x in {-20,-10,...,80}
    {   \draw[shift={(\x,0)},color=black] (0pt,45pt) -- (0pt,-45pt);
    }
    \foreach \x in {-10,0,...,20}
    {   \draw[shift={(\x,0)},color=black] (0,0) node[inner sep=10pt, below, scale=0.9] {\x};
    }
    %\draw[color=orange, ->] (-4,2) -- ++(0,8) node[fill=orange!20, anchor=south, scale=0.8, circle] {A};
    \pic at (-4,0) {bubblelab={label=A,color=orange,fill=orange,length=0.8, scale=0.8}};
    \draw[color=orange, ->] (4,2) -- (4,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {B};
    \draw[color=orange, ->] (14,2) -- (14,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {C};
    \draw[color=orange, ->] (28,2) -- (28,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {D};
    \draw[color=orange, ->] (52,2) -- (52,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {E};
    \draw[color=orange, ->] (72,2) -- (72,10) node[fill=orange!20, anchor=south, scale=0.8, circle] {F};
\end{tikzpicture}
\end{adjustbox}
\end{document}

enter image description here

|improve this answer|||||
  • I had to use a text comparator to see the difference between the two code... I wouldn't have found the problem, searching too far while it was just a problem of space :/ ... thx – Nilcouv Feb 28 at 8:56

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.