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.

Are there any easy way to make something similar to this image in tikz, asympote or similar?

I know the coordinates, to each of the points =)

Simple numberline

The actuall numbers

Ofcourse I know how to solve this, but to do it in tikz or simmilar is new to me.

share|improve this question
add comment

4 Answers

up vote 9 down vote accepted

There is an easy way to do this in TikZ, with the \foreach statement. Like this:

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \noindent
    \begin{tikzpicture}
        \path[draw, thick, ->] (-.3,0) -- (6.3,0);
        \foreach \x in {0,...,6}{
            \path[draw, thick] (\x,0) -- ++(0,-.15) node [below] {\x};
        }
        \foreach \x/\name in {0/A,.6/B,1/C,1.5/D,2/E,2.3/F,3/G,3.3/H,4/I,4.6/J,5/K,5.5/L}{
            \path[draw, fill=blue] (\x,0) circle[radius=2pt] node [above=2 mm, blue] {\name};
        }
    \end{tikzpicture}
\end{document}

You could automate the labeling and make the drawing of the line automated dependent on the coordinates that you enter. This is the basic method though, the result looks like this:

enter image description here

share|improve this answer
add comment

Here an example with pstricks (needs xelatex or dvips)

\documentclass{article}
\usepackage{pst-plot}
\begin{document}
\begin{pspicture}(0,-1)(6,1)
\psline{->}(0,0)(6,0)
\def\dotatline#1#2{%
  \uput[-90](!#1 ){$#2$}
  \psdot(!#1)
}


\dotatline{8 1 3 div exp 0}{8^{\frac{1}{3}}}

\dotatline{5.5 0 exp 0}{5,5^{0}}

\dotatline{21 sqrt 0}{\sqrt{21}}

\dotatline{6 2 1 neg exp mul 0}{6\cdot 2^{-1}}

\end{pspicture}
\end{document}

enter image description here

share|improve this answer
add comment

Instead of providing decimal values for the locations, you can use pgfmathsetmacro to compute the location of where the node to be placed is. The first parameter is a general math expression, and the second parameter is the label to be placed.

Instead of just letters you can also provide math expression to label the points. Also the \PlaceNode macro below accepts an optional first parameter that get applied to the label in case you wish to tweak it slightly as I have for the tab(30) label.

enter image description here

\documentclass[border=5pt,tightpage]{standalone}
\usepackage{tikz}

\newcommand*{\PlaceNode}[3][]{%
    \pgfmathsetmacro{\result}{#2}%
    \node at (\result,0) [fill=red,circle, inner sep=1.5pt] {}; \node at (\result,0) [above, #1] {\scriptsize#3};%
}%
\newcommand*{\PlaceTick}[3][]{%
    \pgfmathsetmacro{\result}{#2}%
    \draw [blue,thick] (\result,0) -- (\result,-0.1) node [below,#1] {#3};
}%

\begin{document}
\begin{tikzpicture}
\draw [thick, blue] (0,0) -- (10,0);

\foreach \x in {0,...,10} {
    \PlaceTick[below]{\x}{$\x$}
}

\PlaceNode{8^(1/3)}{A}
\PlaceNode{5^0}{B}
\PlaceNode{sqrt(21)}{C}
\PlaceNode{tan(30)}{D}
\PlaceNode{15*(2^(-1))}{E}
\PlaceNode{(3/2)^3}{F}
\end{tikzpicture}

\bigskip
\begin{tikzpicture}
\draw [thick, blue] (0,0) -- (10,0);

\foreach \x in {0,...,10} {
    \PlaceTick[below]{\x}{$\x$}
}

\PlaceNode{8^(1/3)}{$8^{\frac{1}{3}}$}
\PlaceNode{5^0}{$5^0$}
\PlaceNode{sqrt(21)}{$\sqrt{21}$}
\PlaceNode[yshift=0.3cm]{tan(30)}{$\tan{30^\circ}$}
\PlaceNode{15*(2^(-1))}{$15 \cdot 2^{-1}$}
\PlaceNode{(3/2)^3}{$\left(\frac{3}{2}\right)^3$}
\end{tikzpicture}
\end{document}
share|improve this answer
add comment

Here is another stab at it, using many of the pstricks bundle packages. As such, it requires either an xelatex or latex->dvips->ps2pdf compilation sequence:

enter image description here

\documentclass{article}
\usepackage{pst-node}% http://ctan.org/pkg/pst-node
\usepackage[nomessages]{fp}% http://ctan.org/pkg/fp
\usepackage{pstricks-add}% http://ctan.org/pkg/pstricks-add
\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\begin{document}

\begin{pspicture}(7,3)
  \SpecialCoor
  \psset{xunit=2cm}% Default x-unit

  % ========== AXIS ==========
  \pcline{->}(-0.5,0)(6.5,0)% Horizontal line

  % ========== NODE DEFINITIONS ==========
  \pnode(0,0){A}% A
  \FPeval{\result}{tan(30*pi/180)}% tan 30 degrees ~ 0.57735026918962576450914878050196
  \pnode(\result,0){B}% B
  \pnode(1,0){C}% C 5.5^0 = 1
  \pnode(1.5,0){D}% D (dummy node)
  \pnode(2,0){E}% E 8^(1/3) = 2
  \pnode(2.3,0){F}% F (dummy node)
  \pnode(3,0){G}% G 6 x 2^{-1} = 3
  \FPeval{\result}{pow(3,3/2)}% (3/2)^3 = 3.375
  \pnode(\result,0){H}% H
  \pnode(4,0){I}% I
  \FPeval{\result}{root(2,21)}% sqrt(21) ~ 4.582575694955840006588047193728
  \pnode(\result,0){J}% J
  \pnode(5,0){K}% K
  \pnode(5.55,0){L}% L (dummy node)

  % ========== NODE PRESENTATION ==========
    \psset{linestyle=solid,linewidth=0.5pt,linecolor=black,fillcolor=blue!60,fillstyle=solid}
    \psforeach{\node}{A,C,E,G,I,K,{6,0}}{\uput{10pt}[d]{0}(\node){\the\psLoopIndex}}% Print index
    \psforeach{\nNode}{0,1,2,3,4,5,6}{\psline(\nNode,0)(\nNode,-5pt)}% Print index line
  \psforeach{\node}{A,B,C,D,E,F,G,H,I,J,K,L}{%
    \pscircle(\node){2.5pt}% Print nodes
    \uput{10pt}[u]{0}(\node){\color{blue!60}\node}% Print label
  }
\end{pspicture}

\end{document}

In the above code, you can modify the xunit to whatever you like, which will stretch out the image horizontally. As-is the horizontal unit distance (from A to C, etc) is 2cm.

share|improve this answer
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.