这个 tikz 图片代码:
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\coordinate (a) at (0, 1);
\node at (a) {\textbullet};
\node[above left] at (a) {$\mathbf{a}$};
\coordinate (b) at (5, 5);
\node at (b) {\textbullet};
\node[above right] at (b) {$\mathbf{b}$};
\draw (a) -- (b);
\coordinate (c) at (-1, 0);
\node at (c) {\textbullet};
\node[above left] at (c) {$\mathbf{c}$};
\draw[dashed] (c) -- (b);
\end{tikzpicture}
\end{document}
产生以下输出:
为什么这两条线不重叠(这是浮点错误造成的吗?),我该如何修复它?
答案1
正如您在上面的评论中所看到的,您的问题与几何无关TikZ
,而是与几何有关(当然,如果我正确理解了您的问题的话)。证明:参见下面的代码并获得结果。
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{backgrounds}
\begin{document}
\begin{tikzpicture}
\draw[help lines] (-1.5,-0.5) grid (5.5,5.5);
\coordinate (a) at (0, 1);
\node at (a) {\textbullet};
\node[above left] at (a) {$\mathbf{a}$};
\coordinate (b) at (5, 5);
\node at (b) {\textbullet};
\node[above right] at (b) {$\mathbf{b}$};
\draw (a) -- (b);
\coordinate (c) at (-1, 0);
\node at (c) {\textbullet};
\node[below right] at (c) {$\mathbf{c}$};
\draw[dashed] (c) -- (b);
% the right position for coordinate c,
% that it to be lying on strait through b and c is (-5/4,0)
\coordinate (d) at (-5/4, 0);
\node at (d) {\textbullet};
\node[below left] at (d) {$\mathbf{c'}$};
\scoped[on background layer]
\draw[dashed,red!30, ultra thick] (d) -- (b);
\end{tikzpicture}
\end{document}