I would like to put a black border around some text information displayed on a plot. And I haven't been successful. The text information is displayed in 2 columns. The first column is right justified with text and the second column is left justified with number values. The number values don't seem to be fully left justified at the end of the box. This is the code I use:
This is somewhat related to another question that was previously asked 4 years ago but without an answer yet:
GNUPLOT screen position at the end of a "set label" command
reset session
mean = 1.85
variance = 961.67
median = 23.12
lowQuartile = .23
upQuartile = 2.25
set yrange[0:1]
set xrange[0:1]
infostat = sprintf("Mean : \nVariance : \nMedian : \nFirst Quartile : \nThird Quartile : ")
infonumber = sprintf(" %6.2f\n %6.2f\n %6.2f\n %6.2f\n %6.2f", mean, variance, median, lowQuartile, upQuartile)
set style textbox 2 opaque fc rgb 0xffff00 noborder
set style textbox 3 transparent fc rgb 0xffff00 border lc "black"
set label 10 infostat at graph .6,.8 right boxed bs 2 front
set label 11 infonumber at graph .6,.8 left boxed bs 2 front
plot NaN notitle
About text alignment in columns, it's probably the easiest to use a monospace font. I had a related question about space for proportional fonts. It seems it's difficult for gnuplot to get back the exact space from the used graphics libraries. So, any attempt to nicely align numbers will most likely fail with proportional fonts, because the space depends on the numbers themselves. See label 3 and 4 in the example below.
Hence, my suggestion for "tabular" labels would be: use a monospace font.
Script:
### text and number alignment in textbox
reset session
mean = 1.85
variance = 961.67
median = 23.12
lowQuartile = .23
upQuartile = 2.25
set yrange[0:1]
set xrange[0:1]
fmt = "% 14s :% 7.2f"
info = sprintf(fmt."\n".fmt."\n".fmt."\n".fmt."\n".fmt, \
"Mean", mean, "Variance", variance, "Median", median, \
"First Quartile", lowQuartile, "Third Quartile", upQuartile)
set style textbox 1 opaque fc rgb 0xffcccc margin 4,4
set style textbox 2 opaque fc rgb 0xccffcc margin 4,4
set label 1 info at graph 0.2,0.8 boxed bs 1 font "Arial"
set label 2 info at graph 0.6,0.8 boxed bs 2 font "Courier New"
set label 3 "1111111.1111111\n2222222.2222222" at graph 0.4,0.4 right font "Arial"
set label 4 "1111111.1111111\n2222222.2222222" at graph 0.8,0.4 right font "Courier New"
plot NaN notitle
### end of script
Result: (from wxt terminal)