I want to create a number line from 0 to 3 with tick marks at every, say, 1/2 or 1/3 or whatever.
I have figured out how to make the whole number part of the number line, but can't figure out the fractional tick marks. How do I improve on the following?
CODE THAT DID NOT WORK
Code: Select all
\documentclass[border=10pt]{article}
\usepackage{tikz}
\begin{document}
%THIS PICTURE OF THIRDS DOES NOT WORK.
%Can you not use fractions in the "foreach" command?
%If not, do I have to approximate with decimals (see below in post)
\begin{tikzpicture}[scale=2]
\draw[-latex] (0,0) -- (4.5,0); % the x-axis
\foreach \x in {0/3,1/3,...,12/3} % tick marks for every 1/3
\draw (\x,4pt) -- (\x,-4pt);
\foreach \x in {0,...,4} % the whole numbers labels
\node [below] at (\x,-0.2) {$\x$};
\end{tikzpicture}
\end{document}
Code: Select all
\documentclass[border=10pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[scale=2]
\draw[-latex] (0,0) -- (4.5,0); % the x-axis
\foreach \x in {0,0.33,0.67,1,1.33,1.67,2,2.33,2.67,3,3.33,3.67,4} % tick marks for every approx. 1/3
\draw (\x,4pt) -- (\x,-4pt);
\foreach \x in {0,...,4} % the whole numbers labels
\node [below] at (\x,-0.2) {$\x$};
\end{tikzpicture}
\end{document}