% !Mode:: “TeX:UTF-8”%確保文檔utf-8編碼
\documentclass[tikz,border=2pt]{standalone}

\begin{document}
\begin{tikzpicture}
%draw the axes
\draw[->] (0,0,0) — (3,0,0) node[anchor=west]{$x$};
\draw[->] (0,0,0) — (0,3,0) node[anchor=west]{$y$};
\draw[->] (0,0,0) — (0,0,3) node[anchor=west]{$z$};
%draw the top and bottom of the cube
\draw (0,0,0) — (0,2,0) — (2,2,0) — (2,0,0) — cycle;
\draw[] (0,0,2) — (0,2,2) — (2,2,2) — (2,0,2) — cycle;
%draw the edges of the cube
\draw[] (0,0,0) — (0,0,2);
\draw[] (0,2,0) — (0,2,2);
\draw[] (2,0,0) — (2,0,2);
\draw (2,2,0) — (2,2,2);
\end{tikzpicture}
\end{tikzpicture}

\end{document}

4 回答4

1
``` \documentclass[tikz,border=2pt]{standalone} \begin{document} \begin{tikzpicture} %draw the axes \draw[->] (0,0,0) -- (3,0,0) node[anchor=west]{$x$}; \draw[->] (0,0,0) -- (0,3,0) node[anchor=west]{$y$}; \draw[->] (0,0,0) -- (0,0,3) node[anchor=west]{$z$}; %draw the top and bottom of the cube \draw (0,0,0) -- (0,2,0) -- (2,2,0) -- (2,0,0) -- cycle; \draw[] (0,0,2) -- (0,2,2) -- (2,2,2) -- (2,0,2) -- cycle; %draw the edges of the cube \draw[] (0,0,0) -- (0,0,2); \draw[] (0,2,0) -- (0,2,2); \draw[] (2,0,0) -- (2,0,2); \draw (2,2,0) -- (2,2,2); \end{tikzpicture} \end{document} ``` 这样就可以了,主要是因为原来的符号问题,画线用 `--`,但是你复制过来的是 `—` 破折号,肯定不对,另外下面还多了一个 `\end{tikzpicture}`。编辑问题的时候代码用代码块包裹起来,不然会出现偏差。 ![](https://pics.latexstudio.net/data/images/202003/f66d47335c0eb1c.jpg)
  • 回复 undefined :哦哦,没仔细看,哈哈,我以为是改完的代码。 – frank.xin 2020-03-28 16:19 回复
  • 哈哈,这个是正方体,又叫正六面体,人家是要正四面体呀~ – zhaochongbin 2020-03-28 16:08 回复
0
正四面体你先自己把4个点的空间坐标先建模出来吧,然后像你的例子一样把各点连起来就好了。 By the way, 用球坐标或者柱坐标建模都会比直角坐标方便。
0
参考如下链接 [如何画正四面体](https://tex.stackexchange.com/questions/174317/creating-a-labeled-tetrahedron-with-tikzpicture "如何画正四面体")
0
\begin{tikzpicture}[z={(-.3cm,-.2cm)}, line join=round, scale=0.6] \draw[color={gray!30}] (1,1,1) -- (-1,1,1) -- (-1,-1,1) -- (1,-1,1) -- (1,1,1) -- (1,1,-1) -- (-1,1,-1) -- (-1,1,1) (1,1,-1) -- (1,-1,-1) -- (1,-1,1); \draw[dashed,color={gray!30}] (-1,1,-1) -- (-1,-1,-1) -- (-1,-1,1) (-1,-1,-1) -- (1,-1,-1); %%%%%%%%%%%% \draw[gray!60,thick] (-1,-1,-1) -- (1,1,-1); \draw[thick] (-1,1,1) -- (1,-1,1) -- (1,1,-1) -- (-1,1,1) -- (-1,-1,-1) -- (1,-1,1); \end{tikzpicture}

你的回答

请登录后回答

你的回答将会帮助更多人,请务必认真回答问题。