3

In the following example, the two attemps to express a node at the intersection of C and the midpoint of A and B is failing. The workaround with creating a separate coordinate works fine, but is there a way to use the single-line version as in the two attempts?

\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}

jII
  • 497
  • The syntax suggested here did not help: https://tex.stackexchange.com/questions/447936/combining-calc-and-perpendicular-coordinates-in-tikz – jII Mar 28 '24 at 17:17

1 Answers1

2

Simply place the second coordinate in curly brackets and not in parentheses.

\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}

enter image description here

AndréC
  • 24,137
  • Thank you @AndreC, how would I have determined this solution myself? I couldn't find an example in the TikZ documentation. – jII Mar 28 '24 at 17:51
  • 1
    To understand this, you have to go into the mysteries of TeX, since TikZ is written in TeX. But I am not a TeX specialist, if you want to understand this, you need to ask the question to specialists. You can ask this question on the chat here, there are all the TeX specialists who will be able to explain this to you competently. Chat LaTeX and friends – AndréC Mar 28 '24 at 18:39
  • As a rule of thumb curly brackets {} are the means in TeX, hence also LaTeX, to mark units, so to say. I.e. we are used to use brackets () e.g. in mathematics to do that. However, a typesetting program can't know if ( is intended to be printed as (, or should it be sth. else? So mathematician Kuth, the originator of TeX, decided, amongst other rules, to use {} for the parser. A parser is a dumb thing, as it can only process byte by byte. // So in short, functionally you did the same by using an extra coordinate: aux or {} is processed first, and its result is used. – MS-SPO Mar 29 '24 at 07:07