The way I see it: you may need those hundreds of hours to understand *everything* about tikz. But do you really need it?LaTexLearner wrote: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.
AFAICS, there's basically just straight lines, some rectangles perhaps, and text involved.
I fiddled around with Stefan's code a bit:
Code: Select all
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
% (rais) the following two commands may not seem necessary; they're just intended to throw a warning in case some other package already defined those macros
\newcommand*\fractionprintnum{}%
\newcommand*\fracpart{}%
\newcommand*\fracyplace{0}% (rais) the vertical offset for the fractions,e.g., 0 for the first bar, -2 for the second bar, and so on
\def\fracpart#1/#2/#3\null{% (rais) similar to \fractionprintnum
% one could catch here, if the mandatory argument to \fractionprint didn't contain a / character at all (arg #2 would be empty)
\frac{#1}{#2}%
}
\def\fractionprintnum#1+#2+#3\null{% (rais) the main goal of this macro is: split the integer part off the fraction part.
% This macro is not intended to be called directly, that's why I'd rather put at least one @ character in its name. OTOH, it's just an example,how things could be done...
% If \fractionprint (see below) gets called with, say, {a+b/c}, the `a' will be put in arg #1 and `b/c' will end up in arg #2 (and arg #3 collects the last + character).
% If \fractionprint gets called with {a/b}, there won't be an integer part. Arg #1 will contain the a/b, arg #2 will be empty, and arg #3 should be empty, too. Then again, arg #3 just plays the role of a garbage collector...
\ifx\relax#2\relax % if there's no integer part
\ensuremath{\fracpart#1//\null}% then the fraction part (if any) will be in arg #1
\else
\ensuremath{#1\fracpart#2//\null}% else output the integer part (#1) and the fraction part will be in arg #2
\fi
}
% The next macro calculates the first argument and uses that position
% to print the next argument
% (rais) since the next argument could be assembled from the first, I skipped the second mandatory argument, see \fractionprintnum above---it makes calling the \fractionprint command a bit easier.
% And then I thought it might be neat to be able to place the fraction below the bar, as well as above...hence there's now an optional argument, too
\newcommand*{\fractionprint}[2][above=0.3cm]{%
\pgfmathparse{3*(#2)}% (rais) jut a bit more space
\draw (\pgfmathresult,\fracyplace+0.2) -- +(0,-0.3)% (rais) tick added and used \fracyplace as y offset
node[blue, #1] {\fractionprintnum#2++\null}% (rais) blame it on my (rather limited) experience with turbo pascal, that I've eliminated the final ; character here ;-)
}
\begin{document}
\begin{tikzpicture}
\filldraw[fill=black!30] (0,0) rectangle (7.5,0.2);% (rais) the gray bar inside. The width (7.5) was calculated as 3 * 5/2.
% The factor of 3 I included, in case your students have to copy everything to paper, first: for the width of 1/3, they can use 1 cm.
\draw[black!20] (7.5, 0) -- +(0,-2);% (rais) just a help line
\draw[semithick] (0,0) rectangle (9,0.2);% (rais) the x-axis as rectangle
\foreach \x in {0,...,3} % tick marks
\draw (3*\x,0.2) -- +(0,-0.3) node[below=0.2cm]{$\x$};
\foreach \x in {0,...,6}% (rais) fractions above
\fractionprint{\x/2};
\fractionprint[below]{1+1/2};
\fractionprint[below, red]{2+1/2};
\filldraw[fill=black!30] (0,-2) rectangle +(7.5,0.2);% (rais) 3 * 10/4.
\draw[semithick] (0,-2) rectangle +(9,0.2);% (rais) the second bar
\foreach \x in {0,...,3} % tick marks
\draw (3*\x,-1.8) -- +(0,-0.3) node[below=0.2cm]{$\x$};
\renewcommand*\fracyplace{-2}% the y offset for the fractions
\foreach \x in {0,...,12}% (rais) quarters
\fractionprint{\x/4};
\foreach \x in {1,2}
\foreach \xb in {1,2,3}
\fractionprint[below]{\x+\xb/4};
% (rais) the following part just demonstrates, how those funny arrows could be drawn. Come to think of it, an adapted version may have found its way inside markings of the tick marks above
\foreach \x/\y in {0/0, 1/0, 2/0, 3/0, 0/-2, 1/-2, 2/-2, 3/-2}
\draw[very thin] (3*\x, \y-0.15) -- ++(0.1,-0.1) -- ++(-0.05,0)
-- ++(0,-0.1) -- ++(0.15,0) -- ++(0,-0.4) -- ++(-0.4,0)
-- ++(0,0.4) -- ++(0.15,0) -- ++(0,0.1) -- ++(-0.05,0) -- cycle;
\end{tikzpicture}
\end{document}
(I did have contact with pascal, C, and a few others, before trying my hand at LaTeX...TeX's what? Stomach?? (see the TeXbook or perhaps TeXbyTopic)
KR
Rainer