Graphics, Figures & TablesNumber Lines with TikZ

Information and discussion about graphics, figures & tables in LaTeX documents.
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Number Lines with TikZ

Post by LaTexLearner »

I'm ready to start making number lines with TikZ. But I have absolutely no idea how to use TikZ. I am still a LaTeX newbie and have ~0 programming experience.

This shows the kind of worksheets I'm trying to create. (Student writing in blue.)
Fractional Number Lines
Fractional Number Lines
pic of number lines.jpg (71.72 KiB) Viewed 8299 times
How should I get started learning TikZ?

Also, how do I put images directly into these threads?

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Sundial
Posts: 57
Joined: Thu Apr 19, 2012 7:28 pm

Number Lines with TikZ

Post by Sundial »

Please, let me know if the enclosed example is satisfactory as first approach. TikZ environment is highly powerful, but too heavy to learn. The 2-row code has been adapted from the monumental guide of Till Tantau (the inventor of TikZ), p. 913 (over 1165): TikZ&PGF,version 3.0.0, 2013 edition. Cheers

Code: Select all

Code, edit and compile here:
% ----- embed.tex ------
\documentclass{article}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{center}
\setlength\PreviewBorder{10pt}
%
%====================================================
\begin{document}
\begin{center}
%-------------------------------
% Fill here -> tikzpicture CODE
\tikz\foreach \x [evaluate=\x as \shade using \x*8] in {0,1,...,8}
\node [fill=red!\shade!yellow, minimum size=0.65cm] at (\x,0) {$\frac{\x}{2}$};
% --- End filling tikzpicture CODE ---
\end{center}
\end{document}
%====================================================
%--- EOF: embed.tex --------
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Attachments
scrsht.png
scrsht.png (5.74 KiB) Viewed 8293 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Number Lines with TikZ

Post by Stefan Kottwitz »

For information to our readers, it's continuing an earlier question: LaTeX for a Fractions Textbook.
LaTexLearner wrote:How should I get started learning TikZ?
The best source is the (huge) TikZ manual. You can open it on your computer by typing texdoc tikz or texdoc pgf at the command prompt.

You could start with the tutorial chapter.
LaTexLearner wrote:Also, how do I put images directly into these threads?
As you did, you attached an image and clicked the link to put it inline.

Perhaps people would continue your code, if you started something, such as drawing a line. I mean, why should each reader want to type a document frame for answering with working code. The more you provide, the easier you make it for readers, the better the chance to get a solution for more complex things.

Stefan
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Number Lines with TikZ

Post by Stefan Kottwitz »

Here I made a sample drawing, comments are in the code.

Code: Select all

Code, edit and compile here:
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
% The next macro calculates the first argument and uses that position
% to print the next argument
\newcommand*{\fractionprint}[2]{%
\pgfmathparse{#1}
\node at (\pgfmathresult,0.5) {$#2$};}
\begin{document}
\begin{tikzpicture}
\draw[latex-latex] (-2,0) -- (3,0);% the x-axis
\foreach \x in {-1,...,2} % tick marks
\draw (\x,0) -- (\x,-3pt);
\foreach \x in {-1,...,3} % the numbers
\node [below] at (\x,-0.1) {$\x$};
\fractionprint{1/2}{\frac{1}{2}}
\fractionprint{1+3/4}{1\frac{3}{4}}
\fractionprint{2+1/3}{2\frac{1}{3}}
\end{tikzpicture}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
fractions.png
fractions.png (5.24 KiB) Viewed 8279 times
Stefan
LaTeX.org admin
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Number Lines with TikZ

Post by LaTexLearner »

Sundial wrote:Please, let me know if the enclosed example is satisfactory as first approach. TikZ environment is highly powerful, but too heavy to learn. The 2-row code has been adapted from the monumental guide of Till Tantau (the inventor of TikZ), p. 913 (over 1165): TikZ&PGF,version 3.0.0, 2013 edition. Cheers
When you say it's too heavy to learn, can you suggest another way of making those graphics?

The Tikz code in this thread does look very complicated.
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Re: Number Lines with TikZ

Post by Johannes_B »

Too hard to learn seems a bit exaggerated, as there are many users of TikZ.

The TikZ/pgf combo is very very powerful, the manual has more than a thousand pages. This can be very intimidating. But is has a quiete good tutorial as well, that gives you some of the basics. The rest is done by daily use, i guess. If you have many graphics, you will enjoy TikZ.

If you have only a handful, you might just as well produce the images with a vector-graphics program. Inkscape is available for free. It also has a TikZ export accessile via a plugin. This might be worth a look.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Number Lines with TikZ

Post by LaTexLearner »

Johannes_B wrote:Too hard to learn seems a bit exaggerated, as there are many users of TikZ.

The TikZ/pgf combo is very very powerful, the manual has more than a thousand pages. This can be very intimidating. But is has a quiete good tutorial as well, that gives you some of the basics. The rest is done by daily use, i guess. If you have many graphics, you will enjoy TikZ.

If you have only a handful, you might just as well produce the images with a vector-graphics program. Inkscape is available for free. It also has a TikZ export accessile via a plugin. This might be worth a look.
When you say "tutorial" are you referring to the "TikZ and PGF Manual for Version 3.0.0" by Till Tantau? I just downloaded it... lol it looks monstrous, lol.

I expect to have about ~200 pages of materials, much of which will be images, though many of those images will be the similar. Probably 4 or 5 templates with many variations on each. Sounds like too many for Inkscape?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Number Lines with TikZ

Post by Stefan Kottwitz »

LaTexLearner wrote:it looks monstrous
Sure, because it's very capable and well documented with a lot of examples. One can get started with reading a short tutorial section and using the rest as a reference. No need to read hundreds of pages of libraries which you don't use.

Large manuals a great. The more explained, the better. The more examples, the better. The more powerful package, the better. It's hardly understandable to reject a long manual just because of the size. I guess you did not mean it that way.
LaTexLearner wrote:I expect to have about ~200 pages of materials, much of which will be images, though many of those images will be the similar. Probably 4 or 5 templates with many variations on each. Sounds like too many for Inkscape?
A strong point of TikZ is that you can "program" 4 or 5 templates and generate a hundred pictures with variations of them. One can use Inkscape with copy & paste, but it's not native LaTeX and especially TikZ styles can be changed globally and consistently with a few clicks in the style definition, while with Inkscape it's hard to modify the appearance of a hundred images.

So, a few and different images: Inkscape. A lot of similar images: TikZ - once created the base drawings the re-using is easy. Though it requires some reading and learning.

Stefan
LaTeX.org admin
LaTexLearner
Posts: 139
Joined: Tue Mar 10, 2015 11:06 am

Re: Number Lines with TikZ

Post by LaTexLearner »

I am, of course, not rejecting the manual on the basis of length. I am, though, a little worried that it will take me hundreds of hours to get even the basics down and it would therefore be faster to use another program. I'm struggling to even make sense of the very first example. Perhaps the manual is written for people who already know LaTeX and programming already?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10323
Joined: Mon Mar 10, 2008 9:44 pm

Number Lines with TikZ

Post by Stefan Kottwitz »

LaTexLearner wrote:not rejecting the manual on the basis of length
Sure, I just see it often from others and it reminds me ;-)
LaTexLearner wrote:Perhaps the manual is written for people who already know LaTeX and programming already?
Let's say, it's for people using LaTeX already. Programming means too much. It uses LaTeX syntax and adds its own syntax which is quite nice I think.

To show that it got popular and to compare the trend with the other great LaTeX drawing package PSTricks, you could use google trends. Here's a screenshot, showing the red TikZ rising:
pstricks-tikz.png
pstricks-tikz.png (39.89 KiB) Viewed 8240 times
Stefan
LaTeX.org admin
Post Reply