在以下示例中,两次尝试表达 C 的交点和 A 和 B 的中点处的节点均失败。创建单独坐标的解决方法可行,但是否有办法像两次尝试一样使用单行版本?
\documentclass[crop,tikz]{standalone}% 'crop' is the default for v1.0, before it was 'preview'
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node[name=A, at={(0,0)}]{A};
\node[name=B, at={(1,0)}]{B};
\node[name=C, at={(0,1)}]{C};
% XXX Failing Attempt 1
% Package tikz Error: + or - expected. [\node[name=D, at={(C -| $(A)!0.5!(B)$)}]]
% \node[name=D, at={(C -| $(A)!0.5!(B)$)}]{D};
% XXX Failing Attempt 2.
% Package pgf Error: No shape named `($(A' is known. [\node[name=D, at={(C -| ($(A)!0.5!(B)$))}]]
% \node[name=D, at={(C -| ($(A)!0.5!(B)$))}]{D};
% Workaround, create a separate auxiliary coordinate.
\coordinate[name=aux, at=($(A)!0.5!(B)$)];
\node[name=D, at=(C -| aux)]{D};
\end{tikzpicture}
\end{document}
答案1
只需将第二个坐标放在花括号中而不是圆括号中。
\documentclass[crop,tikz]{standalone}% 'crop' is the default for v1.0, before it was 'preview'
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node[name=A, at={(0,0)}]{A};
\node[name=B, at={(1,0)}]{B};
\node[name=C, at={(0,1)}]{C};
%% XXX Failing Attempt 1
%% Package tikz Error: + or - expected. [\node[name=D, at={(C -| $(A)!0.5!(B)$)}]]
\node[name=D, at={(C -| {$(A)!0.5!(B)$})}]{D};
%% XXX Failing Attempt 2.
%% Package pgf Error: No shape named `($(A' is known. [\node[name=D, at={(C -| ($(A)!0.5!(B)$))}]]
\node[name=D, at={(C -| {$(A)!0.5!(B)$})}]{D};
% Workaround, create a separate auxiliary coordinate.
\coordinate[name=aux, at=($(A)!0.5!(B)$)];
\node[name=D, at=(C -| aux)]{D};
\end{tikzpicture}
\end{document}