TransWikia.com

draw[Ruler] How to have ifnumn=XYZ to be drawn longer or shorter

TeX - LaTeX Asked on April 25, 2021

Please consider the following code:

% Y-ruler
newcommandyRuler[5]{
path let p1=($(#1)-(#2)$) in 
pgfextra{ pgfmathsetlengthmacro{RasterboxesHeight}{veclen(x1,y1)} } 
[savevalue={h}{RasterboxesHeight}];
pgfmathsetmacroNoYdiv{h/u} % Number of y divisions

draw[Ruler] (#1) coordinate(Y) -- (#2);
foreach n in {0,1,...,NoYdiv}{%%
draw[Ruler] ([yshift=n*u]Y) -- +(#4,0) node[#3, inner sep=1pt]{
ifnumn=1 n,cm else nfi};
}%%
foreach n in {0.1,0.2,...,NoYdiv}{%% 
draw[] ([yshift=n*u]Y) -- +(#5,0);
}%%
}

Which outputs something as such (there are 2 Y-rulers in this case):

yRuler{LLM}{ULM}{right}{4mm}{2mm}
yRuler{LRM}{URM}{left}{-4mm}{-2mm}

enter image description here

As one can see, the 1cm already overlaps perfectly.

It would be great if also the 0s below them could overlap perfectly, as well as the 2s and the 3s above.

How could we adapt the code above to achieve this result? That is, make the draw[Ruler] have longer strokes for all numbers other than 1?

Don’t worry about the exact yshift needed, as long as you can input some variable to play with, I will be very happy.

One Answer

It is the art of breaking down difficult problems into simple cutouts and giving working minimal examples for them, with which one can test and try out (and then integrating their solutions into the more complex overall code).

enter image description here

documentclass[margin=5pt, tikz]{standalone}
usepackage{tikz}
begin{document}
begin{tikzpicture}[]
foreach n in {1,...,5}{
ifnumn=3  draw[yshift=-n cm, red] (0,0) -- (4,0) node[right]{n};
else draw[yshift=-n cm] (0,0) -- (2,0) node[right]{ifnumn=1 n~(it's one) else nfi};
fi}
end{tikzpicture}
end{document}

Answered by cis on April 25, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP