我有以下立方体:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\pgfmathsetmacro{\cubex}{2}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{1}
\draw[red,fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[red,fill=yellow] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[red,fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{tikzpicture}
\end{document}
我想画箭头并像这样标记立方体:
(上面写着a_1 \cdots a_n, b_1 \cdots b_n, c_1 \cdots c_n
)。我怎样才能在 LaTeX 中做到这一点?
答案1
您需要绘制三条平行于三条边的线,.5em
间隔约为,并为每条线添加一个具有适当位置和斜率的标签。请参阅代码中的最后三行。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=1.7,> = latex]
\pgfmathsetmacro{\cubex}{2}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{1}
\draw[red,fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
\draw[red,fill=yellow] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
\draw[red,fill=yellow] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\draw[|<->|,yshift=-.5em] (-\cubex,-\cubey,0)--node[below]{$a_1 \cdots a_n$}++(\cubex,0,0);
\draw[|<->|,xshift=-.5em] (-\cubex,-\cubey,0)--node[above,sloped]{$c_1 \cdots c_n$}++(0,\cubey,0);
\draw[|<->|,shift={(.5em,-.5em)}] (0,-\cubey,0)--node[below,sloped]{$b_1 \cdots b_n$}++(0,0,-\cubez);
\end{tikzpicture}
\end{document}
2-D 版本也更容易实现,如下所示:
\begin{tikzpicture}[scale=1.7, >=latex]
\draw[red,fill=yellow] (0,0)--(2,0)--(2,1)--(0,1)--cycle;
\draw[red,fill=yellow] (2,0)--++(45:.6)--++(0,1)--(2,1)--cycle;
\draw[red,fill=yellow] (2,1)--++(45:.6)--++(-2,0)--(0,1)--cycle;
\draw[|<->|,yshift=-.5em] (0,0)--node[below]{$a_1 \cdots a_n$}(2,0);
\draw[|<->|,xshift=-.5em] (0,0)--node[above,sloped]{$c_1 \cdots c_n$}(0,1);
\draw[|<->|,shift={(.5em,-.5em)}] (2,0)--node[below,sloped]{$b_1 \cdots b_n$}++(45:.6);
\end{tikzpicture}
得到类似的结果: