I have some custom plotting functions that simplify the placement of footnotes and source notes under the plot. It is important that the line length of the footnotes fills up the available space and lines up neatly with the plot, which has a known, fixed width.
Below is a somewhat simplified version of my code for creating a grid containing these notes, with some Frame
s added so you can see the relationship of the length of the text lines to the width of the Grid
cells.
My problem is that, no matter what I do with LinebreakAdjustments
, the lines in the footnote text break far too "soon", and leave far more whitespace than one would see in any other program that lays out text in a text box. How can I fix this? It's the sort of thing my persnickety user base will consider a show-stopper.
Options[SourceNote] = {FootnoteMargin -> 5.7, NoteFontSize -> 14,
LeftCellSize -> 10, TotalSize -> 45, NotesMargin -> 0.8};
Options[GraphNotesGrid] = {FootnoteMargin -> 5.7, NoteFontSize -> 14,
LeftCellSize -> 10, TotalSize -> 45, NotesMargin -> 0.8};
SourceNote[x : {__String}, opts : OptionsPattern[]] :=
With[{fnm = OptionValue[FootnoteMargin], fs = OptionValue[NoteFontSize]},
If[Length[x] == 1,
{DisplayForm[AdjustmentBox[Style["Source:", fs, FontFamily -> "Arial", Black],
BoxMargins -> {{fnm, 0}, {0, 0}}]],
Style[StringTrim[x[[1]] ], fs, FontFamily -> "Arial", Black]},
{DisplayForm[AdjustmentBox[Style["Sources:", fs, FontFamily -> "Arial", Black],
BoxMargins -> {{fnm, 0}, {0, 0}}]],
(* delete empty strings AFTER counting length to allow "Sources: company reports" case *)
Style[ StringJoin @@ Riffle[ Union[DeleteCases[ StringTrim /@ x, ""]], "; "], fs,
FontFamily -> "Arial", Black], " "}] ]
GraphNotesGrid[cf_?MatrixQ, cs : {__String},
opts : OptionsPattern[]] /; Dimensions[cf][[2]] == 2 :=
With[{fnm = OptionValue[FootnoteMargin],
fs = OptionValue[NoteFontSize], l = OptionValue[LeftCellSize],
ts = OptionValue[TotalSize], topm = OptionValue[NotesMargin]},
Grid[Join[(Map[{DisplayForm[AdjustmentBox[
Style[#[[1]], fs, FontFamily -> "Arial", Black],
BoxMargins -> {{fnm, 0}, {0, 0}}]],
Framed@Pane[ Style[#[[2]], fs, Black, LineIndentMaxFraction -> 0,
LinebreakAdjustments -> {1.2, 200, 12, 1, 500}, (* I tried playing with this *)
FontFamily -> "Arial"], (ts - l)* CurrentValue["FontMWidth"]]} &, cf]),
{SourceNote[cs]}], (* real version does do FilterRules*)
Spacings -> {{0, {}, 0}, {topm, {}, 0}},
ItemSize -> {{l, ts - l}, Automatic}, Alignment -> {Left, Top},
Frame -> All, FrameStyle -> Blue] ]
Here is an example:
GraphNotesGrid[{{"*",
"This is a test footnote that is designed to go over several lines \
and demonstrate the crappy line-breaking algorithm. This might or \
might not be long enough. We shall see. "}, {"**",
"This is another very long footnote which you do not need to read \
but do need to notice the line-breaking"}}, {"ABC", "CBS", "NBC"}]