0

I want to create one and two dimensional, normalized numberlines as you can see in this picture:

Example Numberline

I tried it with tikz, but there are so many things that I'm new to. How to make the <- empty, ... ->, how to create mathematical expressions in the four fields, ...

  • 1
    Welcome to TEX.SE, please show is what you have tried so-far. Because that will give us with a head-start. And, please note that this is not a just-do-it-for-me site. – Raaja_is_at_topanswers.xyz Jun 24 '19 at 12:33
  • Because I'm almost kompletly new to latex, I haven't tried that much. I looked through some exaples on this site (e.g. https://tex.stackexchange.com/questions/148252/help-drawing-a-very-simple-number-line-using-tikz) but I have no Idea, how I can transfer this into my desired look. Sorry! – Yosunih Jun 24 '19 at 12:47
  • Please have a look at the tikz documentation. It is very good and you will probably get almost all the way there by yourself. This requires some effort on your end. If you get stuck on any specific part in the process, don't hesitate to ask a question here. As it is, this question does not fit the format of this site. – schtandard Jun 25 '19 at 00:05

1 Answers1

3

One of the reasons why users are not too excited about such questions is that they force the ones who may answer to type in text from a screen shot. This prevents many from answering. Therefore, in the future, always post what you have tried, at the very least this will allow others to just copy these texts. This answer defines a style with which drawing the number line becomes as simple as saying

\draw[ultra thick,numberline={items={occupied/0.4,don't know/0.6}}] (0,3) -- (5,3);

It has several styles and keys that allow you to customize the appearance in many ways.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.pathreplacing,calc,patterns}
\begin{document}
\begin{tikzpicture}[scale=1.2,numberline/.style={/utils/exec=\tikzset{numberline/.cd,#1},postaction={decorate,
 decoration={show path construction,
      lineto code={
       \draw (\tikzinputsegmentfirst) -- (\tikzinputsegmentlast); 
       \edef\mylist{\pgfkeysvalueof{/tikz/numberline/items}}
       \pgfmathsetmacro{\mysum}{0}
       \foreach \XX/\YY in \mylist
       {\pgfmathsetmacro{\mysum}{\mysum+\YY}
       \xdef\mysum{\mysum}}
       \draw[/tikz/numberline/tick]   (\tikzinputsegmentfirst)    
        -- ($(\tikzinputsegmentfirst)!\pgfkeysvalueof{/tikz/numberline/tick length}!-90:(\tikzinputsegmentlast)$) 
        coordinate[pos=0.5] (numberline-0) 
        let \p1=($($(\tikzinputsegmentfirst)!\pgfkeysvalueof{/tikz/numberline/tick
        length}!-90:(\tikzinputsegmentlast)$)-(\tikzinputsegmentfirst)$),\n1={atan2(\y1,\x1)-180} in 
        node[anchor=\n1]{$0$};
       \pgfmathsetmacro{\sumsofar}{0}
       \foreach \XX/\YY [count=\ZZ] in \mylist
       {\pgfmathsetmacro{\sumsofar}{\sumsofar+\YY}
       \xdef\sumsofar{\sumsofar}
       \pgfmathsetmacro{\fraction}{\sumsofar/\mysum}
       \draw[/tikz/numberline/tick] ($(\tikzinputsegmentfirst)!\fraction!(\tikzinputsegmentlast)$) -- 
        ($(\tikzinputsegmentfirst)!\fraction!(\tikzinputsegmentlast)!\pgfkeysvalueof{/tikz/numberline/tick length}!90:(\tikzinputsegmentfirst)$)
        coordinate[pos=0.5] (numberline-\ZZ) 
        let \p1=($($(\tikzinputsegmentfirst)!\pgfkeysvalueof{/tikz/numberline/tick
        length}!-90:(\tikzinputsegmentlast)$)-(\tikzinputsegmentfirst)$),\n1={atan2(\y1,\x1)-180} in
        node[anchor=\n1]{$\pgfmathprintnumber{\fraction}$};
       \draw[/tikz/numberline/arrow] (numberline-\the\numexpr\ZZ-1) -- (numberline-\the\numexpr\ZZ) node[/tikz/numberline/node]{\XX};
       }
      }}}},numberline/.cd,tick/.style={ultra thin},arrow/.style={latex-latex,thin},node/.style={allow upside down=true,auto,swap,sloped,midway,font=\small\sffamily},items/.initial={A/1,B/1},
      tick length/.initial=7pt]
 \draw[ultra thick,numberline={items={occupied/0.4,don't know/0.6}}] (0,3) -- (5,3);
 \draw[ultra thick,numberline={items={occupied/0.6,don't know/0.4}}] (0,0) -- (5,0);
 \begin{scope}[xshift=7cm,pft/.style={align=center,font=\sffamily\small,inner sep=0.5pt,outer sep=0pt}]
  \draw[thin,pattern=dots] (0,0) rectangle (3,2) node[midway,pft]{Occupied $\Omega$\\ $=$occupied} 
    (0,2) rectangle (3,5) node[midway,pft]{Occupied $\Omega$\\ $=$duck}  (3,0) rectangle (5,2) node[midway,pft]{Don't know $\Omega$\\ $=$koala} ;
  \draw[thin,pattern=crosshatch dots]  (3,2) rectangle (5,5) node[midway,pft,fill=white]{Don't know $\Omega$\\ $=$squirrel} ;
  \draw[ultra thick,numberline={items={occupied/0.6,don't know/0.4}}] (0,0) -- (5,0);
  \draw[ultra thick,numberline={items={occupied/0.4,don't know/0.6},tick length=-7pt,node/.append style={above}}] (0,0) -- (0,5);
 \end{scope}
\end{tikzpicture}
\end{document}

enter image description here