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.

Below I have some images i need to 'Tikzify'

I would preffer to learn how to make these, and I will. But for now could anyone please show me how to make these? I am not looking for an exact replica, just something that looks pretty =)

I have just started learning tikz, so this is a bit above my level.

Tree one

Tree two

and


Minimal example below... I did try to create this image. But i just feel everything I do is wrong. Like manually making the tree, as wh!tes suggestion did not quite work. And his tree did not look right.

1) The tree is still not right. somewhat wrong colors (I think I can fix this) The tree sizes is wrong (a ton of work, working it out from my code) The stem is too high, the branches are too wide and so on. the stem is not wide enough, had problems creating a rectangle

2) The lines are not thick enough, i assume i must use some sort of rectangle here aswell.

  1. The underbrace does not quite look right. I therefore think I have to create somewhat of my own.

HEre is my attempt

\documentclass[10pt,a4paper]{article}

\usepackage[hmargin=3cm,vmargin=2cm]{geometry}
\usepackage{tikz}
\usetikzlibrary{calc}% for coordinate calculations
\usepackage{textpos}
\def\drawtree#1#2#3{%#segments, height
  \begin{tikzpicture}
    \path[draw, fill=brown] rectangle (.2,.5) ++(-.1,0) coordinate (base);%draw     stem
    \pgfmathsetlengthmacro{\segWidth}{3#}
    \pgfmathsetlengthmacro{\segHeight}{#2/#1*1.6}
    \foreach \x in {1,...,#1}{%
      \pgfmathsetmacro{\y}{\x-1}
      \path[draw,fill=green] (base) ++({-#2/4*(4/5)^\y},0) -- ++({#2/2*    (4/5)^\y},0) -- ($(base) + (0,\segHeight)$) -- cycle;
      \coordinate (base) at ($(base) + (0,\segHeight/1.6)$);
    }
      \end{tikzpicture}
    }

\begin{document}
\begin{textblock}{1}(-2.7,0){1,1}
\begin{tikzpicture}[scale=0.9]
% Define the coorrdinate of the horizontal line
\coordinate (A) at (0,0);% left end point
\coordinate (B) at (1,0);% start of first yellow line
\coordinate (C) at (5,0);% start of second yellow line
\coordinate (D) at ($(C)+(8,0)$);% tree is 12m to right of (C)
\coordinate (E) at ($(D) + (5,0)$);% end of horizontal line
\coordinate (F) at ($(D)+(0,2/3)$);%
\coordinate (G) at ($(D)+(0,6)$);%
\coordinate (H) at ($(D)+(-1,6-1.2-0.2)$);
\coordinate (I) at ($(D)+(-0.5,6-1.2-0.2)$);
\coordinate (J) at ($(D)+(-2,6-1.2*2-0.2)$);
\coordinate (K) at ($(D)+(-1.3,6-1.2*2-0.2)$);
\coordinate (L) at ($(D)+(-3,6-1.2*3-0.2)$);
\coordinate (M) at ($(D)+(-1.1,6-1.2*3-0.2)$);
\coordinate (N) at ($(D)+(-4,6-1.2*4-0.2)$);
\coordinate (O) at ($(D)+(-0.9,6-1.2*4-0.2)$);
\coordinate (P) at ($(D)+(0.9,6-1.2*4-0.2)$);
\coordinate (Q) at ($(D)+(4,6-1.2*4-0.2)$);
\coordinate (R) at ($(D)+(4,6-1.2*4-0.2)$);
\coordinate (S) at ($(D)+(1.1,6-1.2*3-0.2)$);
\coordinate (T) at ($(D)+(3,6-1.2*3-0.2)$);
\coordinate (U) at ($(D)+(1.3,6-1.2*2-0.2)$);
\coordinate (V) at ($(D)+(2,6-1.2*2-0.2)$);
\coordinate (W) at ($(D)+(0.5,6-1.2-0.2)$);
\coordinate (Z) at ($(D)+(1,6-1.2-0.2)$);
\draw[ultra thick,brown!40!black] (D) -- ($(D) + (0,1)$);

\path[draw,fill=green!50!black]  (G) -- (H) -- (I) -- (J) -- (K) -- (L) -- (M) -- (N) -- (O) -- (P) -- (Q) -- (R) -- (S) -- (T) -- (U) -- (V) -- (W) -- (Z) -- (G);
% First intersting point is (1.6,1.2) from point (B)
\coordinate (Bstart) at ($(B) + (1.6,1.2)$);
% Top of first yellow line is about 5 times further then the first point
\coordinate (Bend) at ($(B) + 5*(1.6,1.2)$);

% Similarily for the second yellow line
\coordinate (Cend) at ($(C) + 5*(1.6,1.2)$);

% For debugging purposes, label each of the points
% When done, comment this \foreach out
\foreach \point in {A, B, C, D, E, Bstart, Bend, Cend} {
    \node at (\point) {\point};
}

\draw [thick, black] (A) -- (E);% Draw the horizontal line

% First yellow line begins at (B) and goes to (Bend)
\draw [ultra thick, blue] (B) -- (Bend);

% Similarily for second yellow line
\draw [ultra thick, blue] (C) -- (Cend);
\end{tikzpicture}
\end{textblock}
\end{document}

As I grew tired of dealing with this tikz nightmare I went ahead and made the figure in geogebra. Barely took me 15 minutes. This is how i want the top image to look

My geogebra attempt

share|improve this question
10  
It's always better to start solving the problem yourself, and when you hit a roadblock, ask a concrete question. The drawing consists mainly of straight lines, so whipping something basic up shouldn't be too much of a problem. Drawing braces has been discussed in tex.stackexchange.com/questions/34446/…. –  Jake Nov 13 '11 at 1:08
    
You could do all of this with coordinates after a quick pen and paper calculation. You'll probably need to "decorate" a line to get those braces. You could define a command for tree that takes height as an argument, which may save you some lines. For a far more complex example of something like that see this. –  qubyte Nov 13 '11 at 4:52

3 Answers 3

This is not really an answer, but more of a comment, but too long to put in a comment.

What follows won't produce the above picture, but it should get you started on how to approach these types or problems. Just as you would if you had to draw this by hand, you need to determine where the important points in your picture are.

  1. For instance, lets say that in the top picture, the starting point of the black horizontal line is at (0,0). We can refer to this as point A via: \coordinate (A) at (0,0);

  2. Similarly the start of the yellow line on the left is about (1,0) to the right and the next one starts at about (5,0): \coordinate (B) at (1,0); and \coordinate (C) at (5,0);

  3. The lower part of the tree is (12,0) to the right of pint (C), and we can use the tikzlibrary calc for this: \coordinate(D)at ($(C)+(12,0)$);

  4. The horizontal line ends about (5,0) to the right of (D): \coordinate (E) at ($(D) + (5,0)$);

That defines all the points on the black horizontal line. Similarly consider the yellow line on the left. The first point on this yellow line relative to point (B) is (1.6,1.2), so we can define this point as \coordinate (Bstart) at ($(B) + (1.6,1.2)$);.

The top of the first yellow line is about 5 times further out, and we can again use the calc library for this: \coordinate (Bend) at ($(B) + 5*(1.6,1.2)$);

Then it is just a matter of connecting the points with \draw commands to get. I used blue instead of yellow as that is easier to see:

enter image description here

I realize that this may not seem like much, but am hoping that it can get you started:

\documentclass[border=5pt,tightpage]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}% for coordinate calculations

\begin{document}
\begin{tikzpicture}
% Define the coorrdinate of the horizontal line
\coordinate (A) at (0,0);% left end point
\coordinate (B) at (1,0);% start of first yellow line
\coordinate (C) at (5,0);% start of second yellow line
\coordinate (D) at ($(C)+(12,0)$);% tree is 12m to right of (C)
\coordinate (E) at ($(D) + (5,0)$);% end of horizontal line

% First intersting point is (1.6,1.2) from point (B)
\coordinate (Bstart) at ($(B) + (1.6,1.2)$);
% Top of first yellow line is about 5 times further then the first point
\coordinate (Bend) at ($(B) + 5*(1.6,1.2)$);

% Similarily for the second yellow line
\coordinate (Cend) at ($(C) + 5*(1.6,1.2)$);

% For debugging purposes, label each of the points
% When done, comment this \foreach out
\foreach \point in {A, B, C, D, E, Bstart, Bend, Cend} {
    \node at (\point) {\point};
}

\draw [thick, black] (A) -- (E);% Draw the horizontal line

% First yellow line begins at (B) and goes to (Bend)
\draw [ultra thick, blue] (B) -- (Bend);

% Similarily for second yellow line
\draw [ultra thick, blue] (C) -- (Cend);
\end{tikzpicture}
\end{document}
share|improve this answer
    
I will attempt to start drawing now. Will be back with comments and such later. Only problem I see now, is how to make the angle, to fill the tree, and propper underbrace. Perhaops it is just me but the underbrace provided by lockstep does not seem that good... Will be back –  N3buchadnezzar Nov 13 '11 at 11:37
    
@N3buchadnezzar: I’d prefer an arrow instead of the under brace: \draw [|<->|] (0,0) -- (1,5); –  Tobi Nov 13 '11 at 12:49

I presume the hardest part is drawing the trees in a nice way. The rest is just some straight lines, an arc and decorations. The nicest solution would be to be able to specify parameters that define the tree. The following example allows you to give the number of segments (triangles) and the height of the tree. It will then draw a tree using some simple rules: the base of the triangles decreases by 20% on each consecutive triangle, the height stays the same though (causing the angles to change). Each triangle has height 1.6 times that required to exactly fill the height, the top 60% of that is covered by the following triangle. These values could become parameters as well, here I just set them in the code. The code looks as follows:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\drawtree#1#2{%#segments, height
  \begin{tikzpicture}
    \path[draw, fill=brown] rectangle (.2,.5) ++(-.1,0) coordinate (base);%draw stem
    \pgfmathsetlengthmacro{\segWidth}{#2/2}
    \pgfmathsetlengthmacro{\segHeight}{#2/#1*1.6}
    \foreach \x in {1,...,#1}{%
      \pgfmathsetmacro{\y}{\x-1}
      \path[draw,fill=green] (base) ++({-#2/4*(4/5)^\y},0) -- ++({#2/2*(4/5)^\y},0) -- ($(base) + (0,\segHeight)$) -- cycle;
      \coordinate (base) at ($(base) + (0,\segHeight/1.6)$);
    }
  \end{tikzpicture}
}
\begin{document}
  \noindent
  \drawtree{4}{12 cm} \drawtree{5}{13 cm}
\end{document}

And the resulting trees:

TikZ trees

The results can be made to look a little better by tuning the parameters. This should show the principle quite well though.

UPDATE: After comments. The color is set as an option to the path using the fill=green option. If you want it a little darker you could specify, for instance, fill=green!40!black. This means: mix 40% green with 60% black. The length of the base is denotes as \segWidth in my code. It is initially set to half of the height, using \pgfmathsetlengthmacro{\segWidth}{#2/2}. You can modify that to make it a different ratio of the height, or just some set number (which breaks the parameterization (is that a word?)). Alternatively, you could add the initial base length as a parameter, by changing it to \def#1#2#3... the third argument could then become the base length. The 20% reduction of base length is done by multiplying with (4/5)^\y. This works out to .8, .8^2, .8^3 ... on consecutive passes. Meaning a reduction of 20% on each pass. You can change the 4/5 fraction to get a different reduction or include it as an additional parameter in the same manner you would for the initial base length discussed above. Finally, the 1.6 in \pgfmathsetlengthmacro{\segHeight}{#2/#1*1.6} and in the calculation for base determine the vertical overlap between triangles. You can increase or decrease that as you desire, or, again use a parameter to define it.

UPDATE: My bad, I had stopped using the \segWidth. I will show you how to do it with parameters to \def. This is the code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\def\drawtree#1#2#3#4#5{%#segments, height, init width, width factor, height factor
  \begin{tikzpicture}
    \path[draw, fill=brown] rectangle (.2,.5) ++(-.1,0) coordinate (base);%draw stem
    \pgfmathsetlengthmacro{\segHeight}{#2/#1*#5}
    \foreach \x in {1,...,#1}{%
      \pgfmathsetmacro{\y}{\x-1}
      \path[draw,fill=green!40!black] (base) ++(-{#3/2*(#4)^\y},0) -- ++({#3*(#4)^\y},0) -- ($(base) + (0,\segHeight)$) -- cycle;
      \coordinate (base) at ($(base) + (0,\segHeight/#5)$);
    }
  \end{tikzpicture}
}
\begin{document}
  \noindent
  \drawtree{4}{12 cm}{6 cm}{4/5}{1.6} \drawtree{6}{12 cm}{8 cm}{.8}{1.5}
\end{document}

And the result:

Modified TikZ trees

share|improve this answer
    
@N3buchadnezzar: Are you sure that you want real trees, maybe you can simplify them to big arrows: \node at (0,0) [shape=isosceles triangle, shape border rotate=90] {}; (needs shapes.geometric library) or \node at (0,0) [shape=single arrow, shape border rotate=90] {}; (needs shapes.arrows library) –  Tobi Nov 13 '11 at 12:55
    
Awesome =) Is there any way to customize the length of the base? I tried looking into the code, and had some problems finding it. Aswell as figuring out how to color the entire tree, no vertical lines inside of it. Gesh I feel so clueless about tikz now... –  N3buchadnezzar Nov 13 '11 at 12:55
    
Those edits did nothing... FAK, Ive been sitting whith this shit all day now, I am so tired... Changing the basewifth manually did nothing to the tree, making an extra argument did nothing to the tree. everything compiles but the baselength wont change ever, sigh... –  N3buchadnezzar Nov 13 '11 at 13:50

Here is a quick and dirty solution to demonstrate that by hand you can act much faster before you decide to automate things:

\documentclass{article}
\usepackage{amsmath,tikz}
\usetikzlibrary{shapes.geometric,decorations.pathreplacing,calc}
\begin{document}
\begin{tikzpicture}
\node[draw,inner sep=1.4mm] (rightangle1) at (135:2.8mm) {.};
\draw[brown!60!black,line width=3mm] (0,0) -- (0,1);
\foreach[count=\countt] \basele / \heig / \elev in {1.4/1/1.2,1.2/1.5/2.1,1/2/3.3,0.7/2.5/4.5} 
{
\node[fill=green!80!black,isosceles triangle,shape border rotate=90,isosceles triangle stretches,%
minimum width=3*\basele cm,minimum height=0.8*\heig cm] (node-\countt) at (0,0.7*\elev) {};
}
\draw[line width=2mm] (3,0) -- (-8,0) -- (-14,-2);
\draw[dotted,line width=1mm] (-8,0) -- (-14,0);
\draw[ultra thick,yellow] (-5,0) -- (node-4.north); 
\draw [decoration={brace,raise=5mm}, decorate] (0,0) -- node [below = 7mm, pos=0.5] {12m} (-5,0);
\draw[ultra thick,yellow] (-7.5,0) -- ($(node-4.north) + (-2.5,0)$);
\draw [decoration={brace,raise=5mm}, decorate] (-5.9,0) -- node [below = 7mm, pos=0.5] {1.6m} (-7.5,0);
\draw [decoration={brace,mirror}, decorate] (-5.9,0) -- node [right = 2mm, pos=0.5] {1.2m} (-5.9,1.2);
\end{tikzpicture}
\end{document}

This code would give the following picture,

enter image description here

There are many points to improve and even to fix. I would recommend you to comment out each line and see what it is doing. I left the adjustment numbers etc. just to show that I have played around with those. The braces I learned from Jake and I also modified wh1t3's foreach loop. Note that, this is generally how you get an idea of what to automate and what to leave out as a manual labor. Once you get the ball rolling, you will learn much faster why and how people around here do what they do as I learn from them everyday.

Please let us know which specific point is causing trouble so people can focus on that.

share|improve this answer
    
I will, I just made the other image in geogebra aswell. Examns sneaking up so I guess I have to put my part time hobby of learning tikz to the side for now ^^ Thanks a bunch for your answer, I will look into it when I have time. –  N3buchadnezzar Nov 14 '11 at 15:15

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.