2

Another TikZ problem: Both vectors a plotted but the second produces an error:

! Dimension too large.
<to be read again> 
              \relax 
l.37   \myvector[text align=center](1,1)
                                    ;
I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can.

I understand that if the vector is small there could be problems with the alignment. But the error occurs even if there is no text.

So I tried to test it:

\ifx\mbftex\empty \def\mbfdecoration{} \else \mbfdecoration{postaction={decorate,decoration={text along path,text align/.expand once=\mbftextalign,text=\mbftext,raise=\mbfraise}}}} /fi

and use it like this :

\centerarct[draw=\mbfcolor,line  width=\mbflinewidth,\mbfdecoration](#2)(20:21:\mbfradius);

but this doesn't work. Ok I could make two definitions of centerarc dependent if text is empty or not. But is there another way? I tried to get a solution with tikzset and styles but this also didn't worked.

\documentclass[10pt]{article}
\usepackage[a4paper,top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending,decorations.text,positioning}

\def\centerarct[#1](#2)(#3:#4:#5)% Syntax: [draw options] (center) (start angle:end angle:radius)
{ \path[#1] ($(#2)+({#5*cos(-#3+90)},{#5*sin(-#3+90)})$) arc [start angle={-#3+90}, end angle={-#4+90}, radius=#5)]; }

\pgfkeys{
    myvector/.is family,
    myvector,
    radius/.initial=4cm,
    line width/.initial =5mm,
    color/.initial=orange,
    text align/.initial=right,
    text/.initial=,
    raise/.initial=0mm
}

\newcommand\myvectorset[1]{\pgfkeys{myvector,#1}}

\def\myvector[#1](#2){
    \myvectorset{#1,
    radius/.get=\mbfradius,
    line width/.get=\mbflinewidth,
    color/.get=\mbfcolor,
    text align/.get=\mbftextalign,
    text/.get=\mbftext,
    raise/.get=\mbfraise
}
\centerarct[draw=\mbfcolor,line  width=\mbflinewidth,postaction={decorate,decoration={text along path,text align/.expand once=\mbftextalign,text=\mbftext,raise=\mbfraise}}](#2)(20:21:\mbfradius);
}

\begin{document}
 \begin{tikzpicture}
  \myvector[](0,0);
  \myvector[text align=center](1,1);
 \end{tikzpicture}
\end{document}

Is there a way to implement something like the following?

\documentclass[10pt]{article}
\usepackage[a4paper,top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc,arrows.meta,bending,decorations.text,positioning}

\begin{document}
 \def\mytext{}
 %\ifx\mytext\empty {\def\mykey{draw=red}} \else {\def\mykey{draw=blue}} \fi % not-solved-1
 \begin{tikzpicture}
  \tikzset{mystyle/.style={draw=red}} works
  %\ifx\mytext\empty {\tikzset{mystyle/.style={draw=red}}} \else {\tikzset{mystyle/.style={draw=blue}}} \fi  % not-solved-2
  %\path[mykey] (0,0) -- (1,1); % part of not-solved-1
  \path[mystyle] (0,0) -- (1,1);
 \end{tikzpicture}
\end{document}

Because this works:

\begin{document}
 \def\mytext{}
 \begin{tikzpicture}
  \ifx \mytext \empty \def\mytest{red} \else \def\mytest{blue} \fi
  \path[draw=\mytest] (0,0) -- (2,1);
 \end{tikzpicture}
\end{document}

But I need to replase the key and its value.

  • Remove the outer curly brackets around the \tikzset{} i.e.\ifx\mytext\empty \tikzset{...} \else \tikzset{...} \fi or whatever. You're putting the changes in a local group when you add the {...}. – cfr Jul 6 '17 at 3:16
  • But your approach is making things needlessly difficult, in my opinion. This can't possibly be an optimal strategy for whatever it is you're trying to do. – cfr Jul 6 '17 at 3:19
  • The main thing is that I want to use the postaction key only if text is there. Otherwise the dimensions too large error occurs. Is the way with 2 different commands better (one for text empty one for with text)? – fatts Jul 6 '17 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.