TIKZ 引数内の特定のチェーンをキャプチャする方法

TIKZ 引数内の特定のチェーンをキャプチャする方法

さまざまな種類の 3D 座標 (ここでは sistemaTd と sistemaT2) を描画するマクロを作成しました。tikz に含まれているシステムを使用すると、Y 軸の凡例の位置が間違っています。

さまざまなファイルで何百回も使用している\eixoため、引数の数を変更せずに方法を見つけたい

の定義には次のようなものが必要だと思います\eixo:

IF #2 contains the chain "sistema" DO pos="below" ELSE pos="right" ENDIF

これは例です:

\documentclass{article}

\usepackage{tikz}
\usepackage{ifthen}
\tikzset{sistemaTd/.style={y={(1 cm,0 cm)},z={(0 cm, 1 cm)},x={(-0.5 cm, -0.5 cm)}}}
\tikzset{sistemaTe/.style={x={(0 cm,1 cm)},y={(1 cm, 0 cm)},z={(-0.5 cm, -0.5 cm)}}}
%eixo{dim}{color, etc} Ejemplo: \texttt{eixo}{black!80,sistemaTd,-latex...}
\newcommand{\eixo}[2]{
    \begin{scope}[->,#2]
        \draw (0,0,0) -- (#1,0,0) node[right]{$X$};
        \draw (0,0,0) -- (0,#1,0) node[below]{$Y$}; %node[below]{$Y$}
        \draw (0,0,0) -- (0,0,#1) node[right]{$Z$};
    \end{scope}
}
\begin{document}
    \begin{tikzpicture}
        \eixo{3}{gray,sistemaTd}
        \begin{scope}[xshift=5.5cm]
            \eixo{3}{gray,sistemaTe}
        \end{scope}
        \begin{scope}[xshift=11cm]
            \eixo{3}{gray} %note the legend of Y axis
        \end{scope}     
    \end{tikzpicture}
\end{document}

答え1

ここで、 を使用して文字列区切り文字をlistofitems検索します。 見つかった場合 (リストの長さが 1 より大きい場合)、指定子が使用され、そうでない場合は が使用されます。#2sistemabelowright

\documentclass{article}

\usepackage{tikz}
\usepackage{ifthen,listofitems}
\tikzset{sistemaTd/.style={y={(1 cm,0 cm)},z={(0 cm, 1 cm)},x={(-0.5 cm, -0.5 cm)}}}
\tikzset{sistemaTe/.style={x={(0 cm,1 cm)},y={(1 cm, 0 cm)},z={(-0.5 cm, -0.5 cm)}}}
%eixo{dim}{color, etc} Ejemplo: \texttt{eixo}{black!80,sistemaTd,-latex...}
\newcommand{\eixo}[2]{
    \begin{scope}[->,#2]
        \draw (0,0,0) -- (#1,0,0) node[right]{$X$};
  \setsepchar{sistema}%
  \readlist\argtwo{#2}%
  \ifnum\listlen\argtwo[]>1\relax
        \draw (0,0,0) -- (0,#1,0) node[below]{$Y$};
  \else
        \draw (0,0,0) -- (0,#1,0) node[right]{$Y$};
  \fi
        \draw (0,0,0) -- (0,0,#1) node[right]{$Z$};
    \end{scope}
}
\begin{document}
    \begin{tikzpicture}
        \eixo{3}{gray,sistemaTd}
        \begin{scope}[xshift=5.5cm]
            \eixo{3}{gray,sistemaTe}
        \end{scope}
        \begin{scope}[xshift=11cm]
            \eixo{3}{gray} %note the legend of Y axis
        \end{scope}     
    \end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

問題を正しく理解していれば、X ラベルの位置も調整するバージョンは次のとおりです。

\documentclass{article}

\usepackage{tikz}
\usepackage{ifthen,listofitems}
\tikzset{sistemaTd/.style={y={(1 cm,0 cm)},z={(0 cm, 1 cm)},x={(-0.5 cm, -0.5 cm)}}}
\tikzset{sistemaTe/.style={x={(0 cm,1 cm)},y={(1 cm, 0 cm)},z={(-0.5 cm, -0.5 cm)}}}
%eixo{dim}{color, etc} Ejemplo: \texttt{eixo}{black!80,sistemaTd,-latex...}
\newcommand{\eixo}[2]{
    \begin{scope}[->,#2]
  \setsepchar{sistema}%
  \readlist\argtwo{#2}%
  \ifnum\listlen\argtwo[]>1\relax
        \draw (0,0,0) -- (#1,0,0) node[right]{$X$};
        \draw (0,0,0) -- (0,#1,0) node[below]{$Y$}; 
  \else
        \draw (0,0,0) -- (#1,0,0) node[below]{$X$};
        \draw (0,0,0) -- (0,#1,0) node[right]{$Y$};
  \fi
        \draw (0,0,0) -- (0,0,#1) node[right]{$Z$};
    \end{scope}
}
\begin{document}
    \begin{tikzpicture}
        \eixo{3}{gray,sistemaTd}
        \begin{scope}[xshift=5.5cm]
            \eixo{3}{gray,sistemaTe}
        \end{scope}
        \begin{scope}[xshift=11cm]
            \eixo{3}{gray} %note the legend of Y axis
        \end{scope}     
    \end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

答え2

軸が水平か垂直かをその場で確認し( を使用calc)、その情報に応じてラベルを添付することができます。こうすることで、座標系を追加したり、その定義を変更したりしても、引き続き機能します。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc}
\tikzset{sistemaTd/.style={y={(1 cm,0 cm)},z={(0 cm, 1 cm)},x={(-0.5 cm, -0.5 cm)}}}
\tikzset{sistemaTe/.style={x={(0 cm,1 cm)},y={(1 cm, 0 cm)},z={(-0.5 cm, -0.5 cm)}}}
%eixo{dim}{color, etc} Ejemplo: \texttt{eixo}{black!80,sistemaTd,-latex...}
\newcommand{\eixo}[2]{
    \begin{scope}[->,#2]
        \draw (0,0,0) -- (#1,0,0) 
        let \p1=($(#1,0,0)-(0,0,0)$),\n1={abs(sin(atan2(\y1,\x1))))} in
        \ifdim\n1<0.4pt [below] \else [right] \fi node  {$X$};
        \draw (0,0,0) -- (0,#1,0) let \p1=($(0,#1,0)-(0,0,0)$),\n1={abs(sin(atan2(\y1,\x1))))} in
        \ifdim\n1<0.4pt [below] \else [right] \fi node {$Y$}; 
        \draw (0,0,0) -- (0,0,#1) let \p1=($(0,0,#1)-(0,0,0)$),\n1={abs(sin(atan2(\y1,\x1))))} in
        \ifdim\n1<0.4pt [below] \else [right] \fi node{$Z$};
    \end{scope}
}
\begin{document}
    \begin{tikzpicture}
        \eixo{3}{gray,sistemaTd}
        \begin{scope}[xshift=5.5cm]
            \eixo{3}{gray,sistemaTe}
        \end{scope}
        \begin{scope}[xshift=11cm]
            \eixo{3}{gray} %note the legend of Y axis
        \end{scope}     
    \end{tikzpicture}
\end{document}

ここに画像の説明を入力してください

関連情報