0

I have problems when I attempt to place text on a "canvas" in a 3D Tikz picture using the code from this answer: TiKZ: How to define new 2D canvas. First, when the text is placed within a scope environment, it is not typeset on the canvas at all (i.e., not with the intended 3D effect). Hence, I used the canvas option seperately for each text node. However, while that results in a 3D effect, the text is not placed where I would expect it. Please see the MWE below. For reference, I have included an x'-axis, a y'-axis, and a square that are placed correctly.

Can anyone please explain what goes wrong and how to fix it?

\documentclass{article}

\usepackage{tikz}
\usepackage{tikz-3dplot}

\makeatletter
\tikzoption{canvas is plane}[]{\@setOxy#1}
\def\@setOxy O(#1,#2,#3)x(#4,#5,#6)y(#7,#8,#9)%
  {\def\tikz@plane@origin{\pgfpointxyz{#1}{#2}{#3}}%
   \def\tikz@plane@x{\pgfpointxyz{#4}{#5}{#6}}%
   \def\tikz@plane@y{\pgfpointxyz{#7}{#8}{#9}}%
   \tikz@canvas@is@plane
  }
\makeatother  
    
\begin{document}

\tdplotsetmaincoords{135}{45}
 
\begin{tikzpicture}[tdplot_main_coords]

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

\begin{scope}[canvas is plane={O(1.5,0,2.5)x(2.4487,0,2.8162)y(1.1838,0,3.4487)}]
\draw[->] (0,0) -- (2,0) node[right] {$x'$};
\draw[->] (0,0) -- (0,2) node[right] {$y'$};
\draw[fill] (1,1) rectangle (2,2);
\node at (0,-2) {Should be on canvas};
\end{scope}

\node[canvas is plane={O(1.5,0,2.5)x(2.4487,0,2.8162)y(1.1838,0,3.4487)}] at (-1,0) {Should};
\node[canvas is plane={O(1.5,0,2.5)x(2.4487,0,2.8162)y(1.1838,0,3.4487)}] at (0,0) {follow};
\node[canvas is plane={O(1.5,0,2.5)x(2.4487,0,2.8162)y(1.1838,0,3.4487)}] at (1,0) {$x'$-axis};

\end{tikzpicture}

\end{document} 

enter image description here

1 Answer 1

2

You should use transform shape to cause the current “external” transformation matrix to be applied to the shape.

\node [transform shape] at (0,-2) {Should be on canvas};

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .