-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: better handling of multi-line text objects in draw #9775
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
In theory https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/backends/backend_pgf.py#L714 should actually measure the sizes correctly for the pgf backend. I guess the problem is that the settings of the pgf backend may change between when matplotlib generates the pgf and when the file is actually compiled. I feel that the proper solution is to have a way for the pgf backend to just tell matplotlib "just pass me the full string, not one line at a time, I (i.e. tex) have a layout manager myself". |
That'd be nice. You can do multiline in pgf if you use the tabular environment, so thats doable. Though I'm not sure what happens to the line spacing if you do that. But I think PGF is the only backend to handle this sort of thing. So you'd need to have special logic in But I'm open to this not being a good solution. Are there other backends that use the text object like PGF does? If its just PGF, I'm not convinced its used often enough to justify changing the rest of the infrastructure to make it work, and this hack looks fine. |
Can't you just do multiline in pgf by using '\' (a normal latex newline) (haven't used pgf for a while but wouldn't be surprised if you could)? In fact if that works I'd suggest just documenting this as the preferred approach for pgf... that'll also get better linespacing (consistent with what tex would do). |
I don't think so. I tried that:
doesn't do anything.
gives:
Works fine. |
https://tex.stackexchange.com/questions/123671/manual-automatic-line-breaks-and-text-alignment-in-tikz-nodes See "Use \\ and align." (and others) |
Yeah, but I don't think that works for PGF. Those are TikZ objects. But I could be doing something else wrong or misunderstanding. |
Sort of hijacking the thread at that point but looks like my pgf install is broken: compiling
(nothing even with matplotlib) gives
any hint? |
I just used the example in #9747 that uses |
Ah, I don't know how to write a latex preamble anymore. My bad. |
https://tex.stackexchange.com/questions/53704/can-i-put-a-line-break-in-pgftext should work though (modulo whatever fixes are needed in the pgf backend)... |
But again, we pass to |
Even worse, I only know that its a |
OK, I'm going to close this. The OP found that properly specifying the fonts in their rcParams did the trick of lining up the characters properly. |
PR Summary
This does a slightly better job with multiline text for at least the PGF backend, and doesn't seem to
break other backends. See #9747
PGF accepts the original text object for positioning and entering etc. However the previous version would not pass the text object if the text string was multi-lined. The text was placed OK, but based on the default renderer font sizes, which could be quite different from the PGF font sizes. This ruined centering of the two title lines in #9747
This attempts to fix that by passing one text object per line. vertical position is taken from the default layout, which assumes a vertical alignment of
bottom
so that gets set.I tried doing this in general, but it breaks other layout choices for single-line text. So it only goes into this layout mode if there are multiple lines.
This fails some hinting tests. Not sure what the status of those are given work @anntzer and @QuLogic are doing on font handling...
PR Checklist