[Tex/LaTex] tikz arc with arrow

arcarrowstikz-pgf

I am drawing the coordinate system using tikz and I intended to use arrow for the arcs \phi and \theta. But when I use -> in the arc options (resulting a proper arc), inside the graph remains an unwanted ^

How to solve this problem? (see "almost MWE" below)

\documentclass{article}
\usepackage{tikz}   %TikZ is required for this to work.  Make sure this exists before the next line
\usepackage{3dplot} %requires 3dplot.sty to be in same directory, or in your LaTeX installation
\usepackage[active,tightpage]{preview}  %generates a tightly fitting border around the work
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{2mm}
\begin{document}
\tdplotsetmaincoords{60}{110}
\pgfmathsetmacro{\rvec}{.8}
\pgfmathsetmacro{\thetavec}{30}
\pgfmathsetmacro{\phivec}{60}
\begin{tikzpicture}[scale=5,tdplot_main_coords]
\coordinate (O) at (0,0,0);
\tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
\draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
\draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
\draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
\draw[-stealth,color=red] (O) -- (P);
\draw[dashed, color=red] (O) -- (Pxy);
\draw[dashed, color=red] (P) -- (Pxy);
\tdplotdrawarc[->]{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
\tdplotsetthetaplanecoords{\phivec}
\tdplotdrawarc[->,tdplot_rotated_coords]{(0,0,0)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
\draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
\draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
\end{tikzpicture}
\end{document}

Best Answer

The problem with the code is that you are using an older version of the 3dplotpackage. It has been replaced with tikz-3dplot which has the functionality you are looking for. Hence the fix is very simple.

\documentclass{article}
  \usepackage{tikz}
% \usepackage{3dplot} % old package
  \usepackage{tikz-3dplot} % new package
  \usepackage[active,tightpage]{preview}
  \PreviewEnvironment{tikzpicture}
  \setlength\PreviewBorder{2mm}
  \begin{document}
    \tdplotsetmaincoords{60}{110}
    \pgfmathsetmacro{\rvec}{.8}
    \pgfmathsetmacro{\thetavec}{30}
    \pgfmathsetmacro{\phivec}{60}
    \begin{tikzpicture}[scale=5,tdplot_main_coords]
      \coordinate (O) at (0,0,0);
      \tdplotsetcoord{P}{\rvec}{\thetavec}{\phivec}
      \draw[thick,->] (0,0,0) -- (1,0,0) node[anchor=north east]{$x$};
      \draw[thick,->] (0,0,0) -- (0,1,0) node[anchor=north west]{$y$};
      \draw[thick,->] (0,0,0) -- (0,0,1) node[anchor=south]{$z$};
      \draw[-stealth,color=red] (O) -- (P);
      \draw[dashed, color=red] (O) -- (Pxy);
      \draw[dashed, color=red] (P) -- (Pxy);
      \tdplotdrawarc[->]{(O)}{0.2}{0}{\phivec}{anchor=north}{$\phi$}
      \tdplotsetthetaplanecoords{\phivec}
      \tdplotdrawarc[->,tdplot_rotated_coords]{(0,0,0)}{0.5}{0}{\thetavec}{anchor=south west}{$\theta$}
      \draw[dashed,tdplot_rotated_coords] (\rvec,0,0) arc (0:90:\rvec);
      \draw[dashed] (\rvec,0,0) arc (0:90:\rvec);
    \end{tikzpicture}
  \end{document}

enter image description here