
我建立了一個繪製不同類型 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
搜尋#2
string-separator sistema
。如果它找到它(由列表長度> 1證明),它使用說明below
符,否則它使用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}
如果我正確理解了這個問題,這裡的版本也調整了 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}