4

How can I do this?

enter image description here

I do not know how to do this. Is it possible to do it in LaTeX or should I create a figure with GeoGebra and insert it?

  • Looks pretty simple for TikZ and friends. Have you tried something already? What are the specifications? And what has that to do with the Table of Contents? – Qrrbrbirlbel Oct 27 '13 at 17:06
  • Is this an illustration to a function domain? – m0nhawk Oct 27 '13 at 17:11
  • I thought of something like tex.stackexchange.com/questions/94246/how-to-draw-intervals @Qrrbrbirlbel – Henfe Oct 27 '13 at 17:14
  • yes, it is the domain of a function @m0nhawk – Henfe Oct 27 '13 at 17:15
18

A little fun with TikZ and PGFkeys.

Code

\documentclass[varwidth]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{
  fromto/.code=\pgfqkeys{/tikz/fromto}{#1}, fromto/.cd,
    from/.initial=0, to/.initial=10,  min/.initial=0, max/.initial=10,
    fromto style/.style={circle, draw, inner sep=+0pt, minimum size=+3pt},
    include/.style={/tikz/fromto/fromto style, fill=black},
    exclude/.style={/tikz/fromto/fromto style, fill=white},
    From/.is choice,
      From/in/.style={/tikz/fromto/from style/.style={fromto/include}},
      From/ex/.style={/tikz/fromto/from style/.style={fromto/exclude}},
      From/no/.style={/tikz/fromto/from style/.style={coordinate, label/.style}},
    To/.is choice,
      To/in/.style={/tikz/fromto/to style/.style={fromto/fromto style, fromto/include}},
      To/ex/.style={/tikz/fromto/to style/.style={fromto/fromto style, fromto/exclude}},
      To/no/.style={/tikz/fromto/to style/.style={coordinate, label/.style}},
    From=no, To=no,
    every fromto picture/.style={x=2.5mm, baseline, >=latex,
      every label/.style={overlay, /utils/exec=\scriptsize}},
    axes/.style={->},
    range/.style={decoration={snake, amplitude=+1pt, segment length=+2pt}, decorate}}
\newcommand*\fromto[1][]{
  \tikzpicture[fromto={#1}, fromto/every fromto picture]
    \draw[fromto/axes/.try] (right:\pgfkeysvalueof{/tikz/fromto/min}) --
      (right:\pgfkeysvalueof{/tikz/fromto/max}) -- ++ (right:10\pgflinewidth);
    \draw[fromto/range/.try] (right:\pgfkeysvalueof{/tikz/fromto/from})
      -- (right:\pgfkeysvalueof{/tikz/fromto/to})
      node[at start, fromto/from style, label=$\pgfkeysvalueof{/tikz/fromto/from}$]{} 
      node[at end, fromto/to style, label=$\pgfkeysvalueof{/tikz/fromto/to}$]{};
  \endtikzpicture}
\begin{document}
\begin{enumerate}
\item \fromto[from=3, From=ex]
\item \fromto[to=7, To=in]
\item \fromto[from=3, From=in, to=6, To=ex]
\item \fromto[min=-5, max=15, from=-3, to=14, From=in, To=ex]
\end{enumerate}
\end{document}

Output

enter image description here

  • When I insert it in my tex, the result was a little small. How could I increase the size? Thank you. @Qrrbrbirlbel – Henfe Oct 28 '13 at 11:39
  • @Henfe: Without compiling the code I think you can just add a 'scale=2' (or any other float > 1) to the \tikzpicture command. I would try \tikzpicture[scale=1.6,fromto={#1}, fromto/every fromto picture]. – Habi Oct 28 '13 at 13:15
  • @Henfe What does “small” mean? I have added x = 2.5mm (default: 1cm) to the every fromto picture style so that it looks more like your picture. You can set this to any other length so that the arrow gets longer or shorter. The nodes with the numbers are set in \scriptsize (see the every label style). Then you can change the line width or the parameters of the snake line. And of course, you can also use scale. – Qrrbrbirlbel Oct 29 '13 at 13:10
2

With PSTricks just for fun!

\documentclass[pstricks,border=15pt]{standalone}
\usepackage{pst-coil}
\psset{coilheight=.4,coilwidth=5pt,coilarm=2.5pt,linejoin=1,arrowinset=0}
\begin{document}

\begin{pspicture}(6,-3)
    % x > 3
    \psline(0,0)(6,0)
    \uput[d](2,0){$3$}
    \pszigzag[coilarmB=5pt]{o->}(2,0)(6,0)
    % x >= 3
    \psline(0,-1)(6,-1)
    \uput[d](2,-1){$3$}
    \pszigzag[coilarmB=5pt]{*->}(2,-1)(6,-1)
    % 2 <= x < 3
    \psline(0,-2)(6,-2)
    \uput[d](2,-2){$2$}
    \uput[d](4,-2){$3$}
    \pszigzag{*-o}(2,-2)(4,-2)
    % x < 2 or x >=3
    \psline(0,-3)(6,-3)
    \uput[d](2,-3){$2$}
    \uput[d](4,-3){$3$}
    \pszigzag[coilarmA=5pt]{<-o}(0,-3)(2,-3)
    \pszigzag[coilarmB=5pt]{*->}(4,-3)(6,-3)
\end{pspicture}}
\end{document}

enter image description here

Notes

  • coilheight is a factor (dimensionless).
  • coilwidth is a length.
  • coilarm is a length.

The formula relating them is given as follows.

If L represents the distance from (x1,y1) to (x2,y2) in \pszigzag(x1,y1)(x2,y2), N represents the number of winding then

coilheight=(L-2*coilarm)/(coilwidth*N).

Fortunately, you don't need to keep the number of winding equal for each case above. That is why we just let the number of winding gets automatically assigned.

If you are interested to assign the number of winding, see my another answer here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.