Tikz의 변수는 정수만 허용합니다.

Tikz의 변수는 정수만 허용합니다.

\xx를 {1,1.5,..10}에서와 같이 정의해야 하지만 \x 변수는 항상 정수를 반환합니다. 어떤 식으로든 이를 수정할 수 있습니다. 미리 감사드립니다.

 \documentclass[borders=2cm]{standalone}
    
        \usepackage{xcolor}
        \definecolor{lava}{rgb}{0.81, 0.06, 0.13}
        \definecolor{myblue}{rgb}{0.0, 0.30, 0.60}
        \usepackage{tikz}
        \usepackage{tikz-3dplot} 
        \newenvironment{mycircuit}{%
    \tdplotsetmaincoords{60}{110}
    \def\y{5} 
    \def\s{1} 
    \def\iAngle{45}
     \pgfmathtruncatemacro{\x}{\xx/2 + \s}
     \pgfmathtruncatemacro{\z}{1 + \s}
    \pgfmathsetmacro{\thetavec}{45}
    \pgfmathsetmacro{\phivec}{60}
    
    \begin{tikzpicture}[tdplot_main_coords,dot/.style = {circle, fill, minimum size=2pt,inner sep=0pt}]
    
    \coordinate (O) at (0,0,0);
    
    \tdplotsetcoord{P}{\x}{\thetavec}{\phivec}
    \tdplotsetcoord{P1}{\z}{\thetavec}{\phivec}
    \tdplotsetcoord{O1}{\s}{\thetavec}{\phivec}
    
    \draw[thick,->] (O)-- (\y,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (O) -- (0,\y,0) node[anchor=north west]{$y$};
    \draw[thick,->] (O) -- (0,0,\y) node[anchor=south]{$z$};
    
    \draw[-stealth,color=myblue,thick,sloped,dashed] (O1) -- node[below]{$\tiny \alpha\mathbf{F}$}(P)node[anchor=north](b){};
    \draw[-stealth,color=lava,thick,sloped] (O1) --node[above]{$\tiny \mathbf{F}$}(P1)node[anchor=north](b){};
     \node[black] at (-\iAngle:\z cm) {$ \tiny 1<\alpha< \infty, \alpha=\x$};
    \end{tikzpicture}
    }
    
    \standaloneenv{mycircuit}
    \begin{document}
    
     \foreach \xx in {2,3,...,10}{\begin{mycircuit} 
     \end{mycircuit}}
    \end{document}

Update,  this is the updated version as per the advices that I received, now I need to round the numbers but I'm getting an error (capacity exceeded

\newenvironment{mycircuit}{%
\tdplotsetmaincoords{60}{110}
\def\y{5} 
\def\s{1} 
\def\iAngle{45}
\pgfmathtruncatemacro{\x}{\xx/2 + \s}
 \pgfmathtruncatemacro{\z}{1 + \s}
\pgfmathsetmacro{\thetavec}{45}
\pgfmathsetmacro{\phivec}{60}
\newcommand*{\MyNum}[1]{%
    \pgfmathprintnumber[
        precision=1,
        fixed zerofill=false,
        ]{##1}}%

\begin{tikzpicture}[tdplot_main_coords,dot/.style = {circle, fill, minimum size=2pt,inner sep=0pt}]

\coordinate (O) at (0,0,0);

\tdplotsetcoord{P}{\xx/2+\s}{\thetavec}{\phivec}
\tdplotsetcoord{P1}{\z}{\thetavec}{\phivec}
\tdplotsetcoord{O1}{\s}{\thetavec}{\phivec}

\draw[thick,->] (O)-- (\y,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (O) -- (0,\y,0) node[anchor=north west]{$y$};
\draw[thick,->] (O) -- (0,0,\y) node[anchor=south]{$z$};

\draw[-stealth,color=myblue,thick,sloped,dashed] (O1) -- node[below]{$\tiny \alpha\mathbf{F}$}(P)node[anchor=north](b){};
\draw[-stealth,color=lava,thick,sloped] (O1) --node[above]{$\tiny \mathbf{F}$}(P1)node[anchor=north](b){};
 \node[black] at (-\iAngle:\z cm) {$\S,\alpha=\MyNum{\pgfmathparse{\xx/4}\pgfmathresult}$};
\end{tikzpicture}
}

\standaloneenv{mycircuit}
\begin{document}
\def\S{1<\alpha< \infty}
%\tiny 
 \foreach \xx in {4,5,...,20}{\begin{mycircuit} 
 \end{mycircuit}}
 \def\S{1>\alpha< 0}
 \foreach \xx in {0.4,0.8,...,1.6}{\begin{mycircuit} 
 \end{mycircuit}}
 
\def\S{-1>\alpha >- \infty}
%\tiny 
 \foreach \xx in {-4,-5,...,-20}{\begin{mycircuit} 
 \end{mycircuit}}
 
\def\S{-1<\alpha< 0}
 \foreach \xx in {-0.2,-0.4,...,-2}{\begin{mycircuit} 
 \end{mycircuit}}
 
 
\end{document}

답변1

덕분에앤드류그리고데이비드 칼라일에 응답하기 위해이 게시물. 이제 해당 매크로를 사용하여 숫자에서 0을 제거할 수 있습니다. 즉, 사용\isinteger

\documentclass[borders=2cm]{standalone}

\usepackage{xcolor}
\definecolor{lava}{rgb}{0.81, 0.06, 0.13}
\definecolor{myblue}{rgb}{0.0, 0.30, 0.60}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\newcommand{\isinteger}[1]{\pgfmathprintnumber[int detect,fixed]{#1}}

\newenvironment{mycircuit}{%
    \tdplotsetmaincoords{60}{110}
    \def\y{5} 
    \def\s{1} 
    \def\iAngle{45}
    \pgfmathtruncatemacro{\x}{\xx/2 + \s}
    \pgfmathtruncatemacro{\z}{1 + \s}
    \pgfmathsetmacro{\thetavec}{45}
    \pgfmathsetmacro{\phivec}{60}
    
    \begin{tikzpicture}[tdplot_main_coords,dot/.style = {circle, fill, minimum size=2pt,inner sep=0pt}]
    
    \coordinate (O) at (0,0,0);
    
    \tdplotsetcoord{P}{\xx/2 + \s}{\thetavec}{\phivec}
    \tdplotsetcoord{P1}{\z}{\thetavec}{\phivec}
    \tdplotsetcoord{O1}{\s}{\thetavec}{\phivec}
    
    \draw[thick,->] (O)-- (\y,0,0) node[anchor=north east]{$x$};
    \draw[thick,->] (O) -- (0,\y,0) node[anchor=north west]{$y$};
    \draw[thick,->] (O) -- (0,0,\y) node[anchor=south]{$z$};
    
    \draw[-stealth,color=myblue,thick,sloped,dashed] (O1) -- node[below]{$\tiny \pgfmathparse{(\xx/2-1 + \s)}\isinteger{\pgfmathresult}\mathbf{F}$}(P)node[anchor=north](b){};
    \draw[-stealth,color=lava,thick,sloped] (O1) --node[above]{$\tiny \mathbf{F}$}(P1)node[anchor=north](b){};
    \node[black] at (-\iAngle:\z cm) {$ \tiny 1<\alpha< \infty, \alpha=\pgfmathparse{(\xx/2-1 + \s)}\isinteger{\pgfmathresult}$};
    \end{tikzpicture}
}

\standaloneenv{mycircuit}
\begin{document}
    \foreach \xx in {2,3,...,10}{\begin{mycircuit} 
    \end{mycircuit}}
\end{document}

여기에 이미지 설명을 입력하세요

관련 정보