Creé una macro que dibuja diferentes tipos de coordenadas 3D (aquí: sistemaTd y sistemaT2). Cuando uso el sistema incluido en tikz la leyenda del eje Y queda en mala posición.
Lo he usado \eixo
cientos de veces en varios archivos, por lo que quiero encontrar una manera sin cambios en la cantidad de argumentos.
Creo que necesito algo como esto en la definición de \eixo
:
IF #2 contains the chain "sistema" DO pos="below" ELSE pos="right" ENDIF
este es el ejemplo:
\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}
Respuesta1
Aquí suelo listofitems
buscar #2
el separador de cadenas sistema
. Si lo encuentra (como lo demuestra una longitud de lista > 1), usa el below
especificador; de lo contrario, usa right
.
\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}
Aquí hay una versión que también ajusta la ubicación de la etiqueta X, si entiendo el problema correctamente:
\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}
Respuesta2
Puedes comprobar (con calc
) en el acto si el eje es más horizontal o vertical y pegar la etiqueta en función de esa información. De esa manera, esto seguirá funcionando si agrega más sistemas de coordenadas y/o cambia su definición.
\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}