线路未到达正确位置

线路未到达正确位置

我正在尝试创建一个角已正确标记的立方体。我有以下 MWE:

\documentclass{standalone}

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{microtype}
\usepackage{mathtools}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \coordinate (o) at (0,0,0);
  \draw[->] (o) -- (5,0,0) node[right] {\(x\)};
  \draw[->] (o) -- (0,5,0) node[above] {\(y\)};
  \draw[->] (o) -- (0,0,5) node[left] {\(z\)};

  \node[left] (a) at (0,0,4) {\(a\)};
  \node[left] (b) at (0,4,4) {\(b\)};
  \node[right] (c) at (4,4,4) {\(c\)};
  \node[below] (d) at (4,0,4) {\(c\)};
  \node[right] (e) at (4,0,0) {\(e\)};
  \node[right] (f) at (4,4,0) {\(f\)};
  \node[above] (g) at (0,4,0) {\(g\)};
  \node[below] (h) at (0,0,0) {\(h\)};

  \begin{scope}[red]
    \draw (a) -- (b);
    \draw (b) -- (c);
    \draw (c) -- (d);
    \draw (d) -- (e);
    \draw (e) -- (f);
    \draw (f) -- (g);
    \draw[dashed] (g) -- (h);
    \draw[dashed] (h) -- (a);
  \end{scope}
\end{tikzpicture}
\end{document}

不幸的是,这会创建一个带有奇怪弯曲线条的立方体(因为线条似乎指向字母的中心而不是指定的坐标):

我怎样才能使线条真正到达指定的坐标并移动文本?

答案1

您使用节点作为红线的坐标。这被视为节点的中心,节点不在“坐标”上。相反,使用带有标签的坐标,如下面的 MWE 所示,您将获得以下图片:

在此处输入图片描述

\documentclass[tikz,
               border=3mm]{standalone}
    \usepackage[utf8]{inputenc}
    \usepackage[T1]{fontenc}
    \usepackage{lmodern}
    \usepackage{microtype}
    \usepackage{mathtools}

\begin{document}
    \begin{tikzpicture}
\coordinate (o) at (0,0,0);
    \draw[->] (o) -- (5,0,0) node[right] {\(x\)};
    \draw[->] (o) -- (0,5,0) node[above] {\(y\)};
    \draw[->] (o) -- (0,0,5) node[left] {\(z\)};
% here I change node to coordinate ...
\coordinate[label=left: $a$] (a) at (0,0,4);
\coordinate[label=left: $b$] (b) at (0,4,4);
\coordinate[label=right:$c$] (c) at (4,4,4);
\coordinate[label=below:$d$] (d) at (4,0,4);
\coordinate[label=below:$e$] (e) at (4,0,0);
\coordinate[label=right:$f$] (f) at (4,4,0);
\coordinate[label=left: $g$] (g) at (0,4,0);
\coordinate[label=below:$h$] (h) at (0,0,0);

    \begin{scope}[red]
\draw   (a) -- (b)  (b) -- (c)   (c) -- (d)
        (d) -- (e)  (e) -- (f)   (f) -- (g);
\draw[dashed]       (g) -- (h)  (h) -- (a);
  \end{scope}
\end{tikzpicture}
\end{document}

相关内容