layout scalebar code metapost # definition scalebar def s_scalebar (expr l, units, txt) = # scale for the scalebar begingroup interim warningcheck:=0; tmpl:=l / (Scale) * tmpscalebar * cm * units / 2; tmpx:=l / (Scale) * tmpscalebar * cm * units / 5; tmph:=5bp*tmpscalebar; % bar height endgroup; pickup PenC; thdraw (-tmpl,0)--(tmpl,0)--(tmpl,-tmph)--(-tmpl,-tmph)--cycle; p:=(0,0)--(tmpx,0)--(tmpx,-tmph)--(0,-tmph)--cycle; for i:=-2.5 step 2 until 2: fill p shifted (i * tmpx,0); endfor; begingroup interim labeloffset:=3.5bp; for i:=0 step (l/5) until (l-1): tmpx:=tmpl * (i * 2 / l - 1); label.bot(thTEX(decimal (i*tmpscalebar)) scaled tmpscalebar,(tmpx,-tmph-(1*tmpscalebar))); endfor; label.bot(thTEX(decimal (l*tmpscalebar) & "\thinspace" & txt) scaled tmpscalebar,(tmpl,-tmph-(1*tmpscalebar))); label.top(thTEX("1 : " & decimal round(Scale*tmpscalebar*100)) scaled tmpscalebar,(0,1*tmpscalebar)); j:=((tmpscalebar-1) div 2)+1; %label.bot(thTEX("B.C.R.A. Grade 3B") scaled j,(0,-tmph*4)); label.bot(thTEX("B.C.R.A. Grade 3B") scaled tmpscalebar,(0,-tmph*4)); endgroup; enddef; endcode endlayout