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.

In the following example, why there is no blue triangle ?

\documentclass[a4paper]{article}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=3cm, right=1.5cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\tikzset{small dot/.style={fill=black,circle,scale=0.3},}

\begin{document}
\begin{tikzpicture}

\coordinate (A0) at (0,0) ;
\coordinate (A1) at (1,0) ;
\coordinate (A2) at (0,1) ;

\draw[fill=red] (A0)--(A1)--(A2)--cycle ;

\draw ($ (A0)!.5!(A1) $) node (E0) {};  
\draw ($ (A1)!.5!(A2) $) node (E1) {};  
\draw ($ (A2)!.5!(A0) $) node (E2) {};  

\draw[fill=blue] (E0)--(E1)--(E2)--cycle ;

\end{tikzpicture}
\end{document}

enter image description here

It is just a simple sample of the problem I have. As I need to use let...in... to calculate between ! ! coefficient, I use this definition of nodes for the Ex nodes. If there is another way or how to correct the blue triangle drawing.

One can tcheat :

\draw ($ (A0)!.5!(A1) $) node (E0) {};  
\draw ($ (A1)!.5!(A2) $) node (E1) {};  
\draw ($ (A2)!.5!(A0) $) node (E2) {};  

\coordinate (B0) at (E0) ;
\coordinate (B1) at (E1) ;
\coordinate (B2) at (E2) ;


\draw[fill=blue] (B0)--(B1)--(B2)--cycle ;

works fine, but why i doesn't work at first time ?

share|improve this question
1  
Use coordinate instead of node to define E0, E1 and E2. –  Paul Gaborit Feb 26 at 12:56
    
See also tex.stackexchange.com/q/4057/86 –  Loop Space Feb 26 at 12:59

3 Answers 3

up vote 5 down vote accepted

nodes are not geometric points but occupy space even if they don't have content. This is because they have inner sep and outer separations. When you artie

\draw[fill=blue] (E0)--(E1)--(E2)--cycle ;

you are not giving from which point of node the lines should be drawn as no anchors are specified in the above line of code. Please note that a coordinate is a geometric point and thus you can draw straight from it. Therefore to draw from a node, a proper anchor must be specified like (E0.center). On the other hand, instead of a node, you can define a coordinate straight away as ferahfeza did in his answer, or simply define node as a coordinate in the following manner:

node[coordinate] (E0) {};

or

node[inner sep=0pt,outer sep=0pt] (E0) {};

Both of these work. But if you adopt the latter, you still have to give the anchors like (E0.center).

A sample code:

\documentclass[a4paper]{article}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=3cm, right=1.5cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

\tikzset{small dot/.style={fill=black,circle,scale=0.3},}

\begin{document}
\begin{tikzpicture}

\coordinate (A0) at (0,0) ;
\coordinate (A1) at (1,0) ;
\coordinate (A2) at (0,1) ;

\draw[fill=red] (A0)--(A1)--(A2)--cycle ;

\path ($ (A0)!.5!(A1) $) node[inner sep=0pt,outer sep=0pt] (E0) {};
\path ($ (A1)!.5!(A2) $) node[inner sep=0pt,outer sep=0pt] (E1) {};
\path ($ (A2)!.5!(A0) $) node[inner sep=0pt,outer sep=0pt] (E2) {};

\draw[fill=blue] (E0.north)--(E1.center)--(E2.east)--cycle ;

\end{tikzpicture}
\end{document}

enter image description here

Please note that, instead of giving center as the anchor from which to draw, I have chosen appropriate anchors (in a failed attempt) so that the blue triangle corners don't protrude out of the red triangle. Moral is, when you want coordinate, define one and not nodes.

share|improve this answer

A compact solution without calc based on default options.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=5]
\draw[fill=red]   (0,0) -- coordinate (E0)(1,0) 
                        -- coordinate (E1)(0,1) 
                        -- coordinate (E2) 
                           cycle ;   
\draw[fill=blue] (E0)--(E1)--(E2)--cycle ;
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thank you Alain. The solution must but let ... in syntaxly compatible. The best, for what I have to do, was \draw[coordinate] ($ (A0)!.5!(A1) $) node (E0) {};. –  Tarass Feb 26 at 15:02

Define node's as coordinate:

\documentclass[a4paper]{article}
\usepackage[marginparsep=3pt, top=2cm, bottom=1.5cm, left=3cm, right=1.5cm]{geometry}

\usepackage{tikz}
\usetikzlibrary{calc,intersections}

%\tikzset{small dot/.style={fill=black,circle,scale=0.3},}

\begin{document}
\begin{tikzpicture}

\coordinate (A0) at (0,0) ;
\coordinate (A1) at (1,0) ;
\coordinate (A2) at (0,1) ;

\draw [fill=red] (A0)--(A1)--(A2)--cycle ;

\coordinate (E0) at ($ (A0)!.5!(A1) $);  
\coordinate (E1) at ($ (A1)!.5!(A2) $);  
\coordinate (E2) at ($ (A2)!.5!(A0) $)  ;  

\draw [fill=blue] (E0)--(E1)--(E2)--cycle ;

\end{tikzpicture}
\end{document}
share|improve this answer
    
I was my firt thaught but I need to use let...in to calculate the coordinates and none of this works : \coordinate let \p1=(A0) in (E0) at ($ (A0)!.5!(A1) $); \coordinate (E1) at \p1=(A0) in ($ (A1)!.5!(A2) $); . This examples are useless, but it's just for example. –  Tarass Feb 26 at 13:04
    
But one can tcheat, I add an edit. –  Tarass Feb 26 at 13:07
    
Sorry I edited your message instead of mine, excuse me please. And thank you. –  Tarass Feb 26 at 13:12
1  
I erroneously approved Tarass edit. @Tarass: the modification you're suggesting is working, but not in your original example. Though, even your original example could work: add the option [coordinate] to all nodes. Then, have a look to the difference between nodes and coordinates: on this site there are good references. –  Claudio Fiandrino Feb 26 at 13:12
    
@Claudio Fiandrino: I check no difference between my cheat and your good solution. I keep yours ;-) thank you. –  Tarass Feb 26 at 13:18

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.