Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have two nodes which I want to define to be opposite corners of a rectangle. I would like to be able to define nodes at the other pair of opposite corners.

I tried the following, but it gives me errors:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\pagestyle{empty}
\begin{document}

%% ATTEMPT 1
%% ERROR: doesn't match its definition
\begin{tikzpicture}
  \node (A) at (0,0) {1};
  \node (C) at (5,3) {3};
  \node (B) at ($ (A) ! (C) ! ($ (A) + (1,0) $) $) {B};
\end{tikzpicture}

%% ATTEMPT 2
%% ERROR: doesn't match its definition
\begin{tikzpicture}
  \node (A) at (0,0) {1};
  \node (C) at (5,3) {3};
  \node (tB) at ($ (A) + (1,0) $ ) {tB};
  \node (B) at ($ (A) ! (C) ! (tB)$) {B};
\end{tikzpicture}

\end{document}

Why isn't my projection working?

share|improve this question
add comment

2 Answers

up vote 9 down vote accepted

Perhaps the simplest way is to use the perpendicular coordinate system:

\documentclass{article}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}

\begin{tikzpicture}
  \node (A) at (0,0) {1};
  \node (C) at (5,3) {3};
  \node (B) at (A.center|-C.center) {2};
  \node (D) at (A.center-|C.center) {4};
\draw[red] (A.center) -- (B.center) -- (C.center) -- (D.center) -- (A.center);
\end{tikzpicture}

\end{document}

enter image description here

(<name1>|-<name2>) has the x-coordinate of <name1> and the y-coordinate of <name2>.

(<name1>-|<name2>) has the x-coordinate of <name2> and the y-coordinate of <name1>.

share|improve this answer
    
This is extremely useful. Where in the manual can I find this documentation? In other words, what topic is this discussed under? –  A.Ellett Aug 12 '13 at 23:49
2  
@A.Ellett Section "Coordinate system perpendicular", pages 130-131 of the PGF manual. –  Gonzalo Medina Aug 12 '13 at 23:51
add comment

Apparently the calc library doesn't like some of the spaces in the coordinate calculation, when I remove them both your examples work, e.g.

\node (B) at ($(A)!(C)!($(A)+(1,0)$)$) {2};
\node (D) at ($(A)!(C)!($(A)+(0,1)$)$) {4}; 

More specifically, as noted by Gonzalo, it is the spaces in ! (<node name>) ! that causes the error, so

\node (B) at ( $ (A) !(C)! ( $ (A)+(1,0) $ ) $ ) {B};
\node (D) at ( $ (A) !(C)! ( $ (A)+(0,1) $ ) $ ) {D};

will also work.

Complete code

\documentclass[border=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
  \node (A) at (0,0) {1};
  \node (C) at (5,3) {3};
  \node (B) at ($(A)!(C)!($(A)+(1,0)$)$) {2};
  \node (D) at ($(A)!(C)!($(A)+(0,1)$)$) {4};
  \draw [red] (A) -- (B) -- (C) -- (D) -- (A);
\end{tikzpicture}
\end{document}

output of code above

share|improve this answer
    
Thanks for explaining my syntax error. –  A.Ellett Aug 13 '13 at 0:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.