# Creating several rulers with TikZ

I am trying to draw 14-meters worth of centimeter-scale rulers, one meter at a time. I hope to print these in adhesive paper to measure something, but that's neither here nor there.

So far I have this code running (MWE) which yields one-meter worth of ruler. I've attached an image of about 22-cm of lenght.

\documentclass[12pt]{standalone}

\renewcommand*\familydefault{\sfdefault}

\renewcommand\familydefault{\sfdefault}
\usepackage[T1]{fontenc}

\usepackage{tikz}

\begin{document}

\begin{tikzpicture}

% \foreach \i in {0,100,...,130}

% Draw Minor tick lines

\foreach \x in {99,97,...,1}
\draw [color=red, line width=6mm](\x cm,0cm) -- (\x cm ,1.5cm)
node[color=red, rotate=90, anchor=west] {\x};

\foreach \x in {100,98,...,0}
\draw [color=black, line width=6mm](\x cm,0cm) -- (\x cm ,1.5cm)
node[color=black, rotate=90, anchor=west] {\x};

Draw Major tick lines

\foreach \x in {100,90,...,0}
\draw [color=black,line width=6mm] (\x cm,4cm) -- (\x cm ,0cm)
node[anchor=north] {\Huge \textbf{\x}};

\foreach \x in {95,85,...,5}
\draw [color=red, line width=6mm] (\x cm,4cm) -- (\x cm ,0cm)
node[anchor=north] {\Huge \textbf{\x}};

% Draw main axis
%  \draw [line width=6mm](0cm, \i cm) -- coordinate (x axis mid) (100cm,\i cm);
\draw [line width=6mm](0cm, 0 cm) -- coordinate (x axis mid) (100cm, 0 cm);

\end{tikzpicture}

\end{document}


I am facing a few problems.

1. I need the numbers to increase from right to left. Right now they are increasing from left to right, despite my specifying the \foreach sequence in decreasing order. How do I accomplish this?
2. The ends of the rulers are not mitered. I tried using the join=miter option in the \draw command, to no effect.
3. Finally, how do I use the \foreach command (if at all) to go from having a single ruler to having fourteen rules stacked vertically, with the right numbering. I managed to accomplish repeating the ruler axis (as you can see commented on the code) but kept getting horrible errors when I tried to do the same with the tick marks and nodes.

There are other things that I can live with, like having the overlapping minor tick mark numbers painted over by the major tick marks, but knowing how to specify the right conditionals to prevent this would be great.

-
1. Yes, of course. Just because you draw from the right to the left, doesn’t mean that the labels change. But it easier just to have the x axis from the right to the left: [x=-1cm] (and use the coordinate system from TikZ). 2. There is no miter cap, only round, rect and the default butt: line cap=rect. 3. You want fourteen rules on one paper or on fourteen papers? –  Qrrbrbirlbel Jun 28 '13 at 4:05
Fourteen rulers on a single sheet of paper. This will eventually be plotted on a continuous feed plotter that holds paper slightly larger than 1.20 meters in width. –  Ricardo Jun 28 '13 at 4:15
2. Using the cap=rect option on the black major tick lines gave the results I was hoping for. 1. I am having trouble figuring out where to put the [x=-1cm] option. How can I be sure that everything will be to scale if I leave it up to the TikZ coordinate system? –  Ricardo Jun 28 '13 at 4:21

1. The order in the \foreach loop has no bearing on the order of drawing. If you specify (\x cm,0cm), then the coordinate is at (\x cm,0cm) (in the canvas system).
I suggest simply to invert the x direction of the TikZ coordinate system: x=-1cm. This means that if you do not specify a unit for the x variable of a coordinate, TikZ will multiply that number with -1cm. Of course, you could have simply used -\x cm but this solution is a little bit more flexible.

2. line cap=rect makes the same line end as butt (the default) just extended for half the line width.

3. We simply enclose one meter in another \foreach loop that goes from 0 (the first meter) to 13 (the fourteenth meter). The first step is to yshift, for the meter 0 about 00cm, then 10cm up to 130cm. If you want a different shift, i.e. distance between the meter, you can use PGF math: yshift=\i*7cm.

## Code

\documentclass[tikz,convert=false,12pt]{standalone}
\renewcommand*\familydefault{\sfdefault}
\renewcommand\familydefault{\sfdefault}
\usepackage[T1]{fontenc}
\begin{document}
\begin{tikzpicture}[x=-1cm,line cap=rect]
\foreach \i in {0,...,13}{
\tikzset{yshift=\i0cm}

\foreach \x in {1,3,...,99}
\draw [color=red, line width=6mm](\x,0cm) -- (\x,1.5cm)
node[color=red, rotate=90, anchor=west] {\pgfmathprint{int(\x+\i*100)}};

\foreach \x in {0,2,...,98}
\draw [color=black, line width=6mm](\x,0cm) -- (\x,1.5cm)
node[color=black, rotate=90, anchor=west] {\pgfmathprint{int(\x+\i*100)}};

\foreach \x in {0,10,...,100}
\draw [color=black,line width=6mm] (\x,4cm) -- (\x,0cm)
node[anchor=north] {\Huge \textbf{{\pgfmathprint{int(\x+\i*100)}}}};

\foreach \x in {5,15,...,95}
\draw [color=red, line width=6mm] (\x,4cm) -- (\x,0cm)
node[anchor=north] {\Huge \textbf{\pgfmathprint{int(\x+\i*100)}}};

\draw [line width=6mm](0, 0cm) -- coordinate (x axis mid) (100,0cm);
}
\end{tikzpicture}
\end{document}


## Output

-
Thank you very much for the kind explanations. None of these ideas were obvious to me, so thank you for taking the time to explain them to me. –  Ricardo Jun 28 '13 at 4:52