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.

Two path names inside intersections are not working. Only one macro seems to work. I have tries all the combinations of macro expansion but in vain. In the following 'h\x and \vy' is not working. It is weard that the first parameter 'h\x' cannot include any macro. Is there any flaw in intersections? Thanks in advance.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
  \begin{tikzpicture}
    \draw[name path=h1] (0,1) --  ++(3,0);
    \draw[name path=h2] (0,2) -- ++(3,0);
    \draw[name path=v1] (1,0) -- ++(0,3);
    \draw[name path=v2] (2,0) -- ++(0,3);
    \foreach \x in {1,2}
    \foreach \y in {1,2}
    \draw[fill,red,name intersections={of= h1 and v\y}] (intersection-1) circle (2pt);
    %\draw[fill,red,name intersections={of= h\x and v\y}] (intersection-1) circle (2pt);% macro h\x doesn't work, why?
  \end{tikzpicture}
\end{document}

intersections

share|improve this question
add comment

1 Answer

up vote 4 down vote accepted

You'll have to enclose the first coordinate in {...}:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}

\begin{document}
  \begin{tikzpicture}
    \draw[name path=h1] (0,1) --  ++(3,0);
    \draw[name path=h2] (0,2) -- ++(3,0);
    \draw[name path=v1] (1,0) -- ++(0,3);
    \draw[name path=v2] (2,0) -- ++(0,3);
    \foreach \x in {1,2}
    \foreach \y in {1,2}
    \draw[fill,red,name intersections={of= {h\x} and v\y}] (intersection-1) circle (2pt);
  \end{tikzpicture}
\end{document}
share|improve this answer
    
It works! Amazing. Thanks Jake. –  gnoejh Sep 21 '12 at 20:11
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.