2

I would like to insert some leading whitespace into some of my legend labels (problem is the same for other types of labels) with latex turned on. However, any leading whitespace that I enter is being ignored (see MWE and image below). An ugly workaround would be to enter a leading . (inspired by this Q&A). That's not pretty, though.

Any idea how I could get this to work properly? Can it even be done, or should I look into raising an issue with matplotlib?

MWE:

import matplotlib.pyplot as plt
plt.rcParams['text.usetex'] = True

fig = plt.figure()
plt.plot([], label="~ tilde")
plt.plot([], label="\, comma")
plt.plot([], label="\quad quad")
plt.plot([], label="\hphantom{whitespace} hphantom")
plt.plot([], label=".\hphantom{whitespace} ugly leading dot")
plt.xlabel("\hphantom{whitespace} xlabel")
plt.legend()

leading white space in matplotlib legend with latex

Zaus
  • 738
  • 10
  • 20
  • Hmm, would `\hspace*{1em}` work? If you aren't using transparency, could you use the "ugly dot" with white colour? https://stackoverflow.com/q/9169052/683329 – Jiří Baum Aug 18 '20 at 00:32
  • 1
    @sabik Nope, `\hspace*{1em}` (or any hspace) is not working either. – Zaus Aug 18 '20 at 00:58
  • 1
    @sabik I tried fiddling with the textcolor, but using `\usepackage{color}` is a whole other can of worms. The suggestions about changing the textcolor from that Q&A don't work for me, they mess up line spacings. – Zaus Aug 18 '20 at 01:12
  • I can't test myself, but maybe try `\mbox{}\hphantom{whitespace} ugly leading dot` – samcarter_is_at_topanswers.xyz Aug 18 '20 at 08:37
  • @samcarter_is_at_topanswers.xyz Good idea, but nope, `\mbox{}` is being ignored as well... :( – Zaus Aug 18 '20 at 09:18

0 Answers0