![如何在 TikZ 中垂直和水平对齐坐标](https://linux22.com/image/391396/%E5%A6%82%E4%BD%95%E5%9C%A8%20TikZ%20%E4%B8%AD%E5%9E%82%E7%9B%B4%E5%92%8C%E6%B0%B4%E5%B9%B3%E5%AF%B9%E9%BD%90%E5%9D%90%E6%A0%87.png)
我有一些无理坐标的点,因为我混合使用了极坐标和笛卡尔坐标。我想将一个坐标指定为一个事物的 x 值和另一个事物的 y 值。
在这个特定的例子中,我希望左边的两条线具有相同的左端点。
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (left) at (155:2);
\coordinate (top) at (65:2);
\coordinate (bottom) at (245:2);
\coordinate (right) at (335:2);
\coordinate (leftEdge) at ($ (left) + (-2,0) $);
\coordinate (bottomEdge) at ($ (bottom) + (0,-2) $);
\path[draw=black] (left) -- (top) -- (right) -- (bottom) -- cycle;
\path[draw=blue] (left) -- (leftEdge);
\path[draw=black] (bottom) -- (bottomEdge);
\path[draw=red] (bottom) -- ++(-2,0);
\end{tikzpicture}
\end{document}
我认为有一种方法可以做到这一点(leftEdge.x,bottom.y)
,但我一直无法让它发挥作用。
我怎样才能使红色边缘到达蓝色边缘的左边?
答案1
在您的示例中,您需要做的就是说\path[draw=red] (bottom) -- (bottom-|leftEdge);
。这个很好的答案为您提供了有关此语法的非常好的讨论。
\documentclass[tikz]{standalone}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (left) at (155:2);
\coordinate (top) at (65:2);
\coordinate (bottom) at (245:2);
\coordinate (right) at (335:2);
\coordinate (leftEdge) at ($ (left) + (-2,0) $);
\coordinate (bottomEdge) at ($ (bottom) + (0,-2) $);
\path[draw=black] (left) -- (top) -- (right) -- (bottom) -- cycle;
\path[draw=blue] (left) -- (leftEdge);
\path[draw=black] (bottom) -- (bottomEdge);
\path[draw=red] (bottom) -- (bottom-|leftEdge);
\end{tikzpicture}
\end{document}