In the following code (the real code has a lot more elements), I am trying to get the legend to line up vertically on the colons or on the percentage numbers. I've tried various HTML tricks, like adding ' ' to the legend strings, but these often overcorrect. Any suggestions appreciated. Thanks!
struct plotControl myPlot; myPlot = plotGetDefaults("XY"); struct plotAnnotation myAnnotation; myAnnotation = annotationGetDefaults(); plotcanvassize("in",9|6); fontsize = 18; plotSetTicLabelFont(&myplot, "arial", fontsize, "black"); plotsetylabel(&myplot, "Proportion Surviving", "arial", fontsize, "black"); plotsetxlabel(&myplot, "Days", "arial", fontsize, "black"); plotsetyrange(&myplot, 0, 1, .1, .2); plotsetxrange(&myplot, 0, 28, 7, 0); let string lineclrs = {"#0072b5", "#0072b5"}; linetype = 1 | 3; xfake = seqa(1000,1,5); yfake = rndn(5,2); legstr1 = "IC:" $+ ftos(100*.118, "*.*lf", 3,1) $+ "%"; legstr2 = "DC:" $+ ftos(100*.344, "*.*lf", 3,1) $+ "%"; legstr = legstr1 $| legstr2; plotsetlinestyle(&myplot, linetype); plotsetlegendfont(&myplot, "arial", fontsize, "black"); plotsetlegend(&myplot, legstr, "bottom left", 1); plotaddxy(myplot, xfake, yfake);
1 Answer
0
The main problem here is that Arial is a proportional font. Each character takes up a different width. If you use a monospace font, it will be much simpler to line them up. In most cases, using a monospace font is the best choice.
However, if you are dead set on using Arial, there is a hack you can try. You can add some extra letters that you style to be white so they don't show. For example:
legstr1 = "<span style=\"color:white\">ii</span>IC:" $+ ntos(100*.118, 3) $+ "%"; legstr2 = "DC:" $+ ntos(100*.344,3) $+ "%";
Makes the colons line up just about perfectly on my monitor. I can't guarantee that it will be the same on other screens, etc.
Your Answer
1 Answer
The main problem here is that Arial is a proportional font. Each character takes up a different width. If you use a monospace font, it will be much simpler to line them up. In most cases, using a monospace font is the best choice.
However, if you are dead set on using Arial, there is a hack you can try. You can add some extra letters that you style to be white so they don't show. For example:
legstr1 = "<span style=\"color:white\">ii</span>IC:" $+ ntos(100*.118, 3) $+ "%"; legstr2 = "DC:" $+ ntos(100*.344,3) $+ "%";
Makes the colons line up just about perfectly on my monitor. I can't guarantee that it will be the same on other screens, etc.