ภาพรวม
LaTeX จัดการช่องว่างในโหมดคณิตศาสตร์อัตโนมัติ แต่บางครั้งอาจต้องการปรับช่องว่างด้วยตนเอง Matplotlib รองรับคำสั่ง spacing ของ LaTeX
คำสั่งช่องว่างใน LaTeX
\;– thick space (กว้าง)\:– medium space (ปานกลาง)\,– thin space (บาง)\!– negative thin space (ลบช่องว่าง/ดึงให้ใกล้กัน)
ตัวอย่างเปรียบเทียบ
ใช้ \! เพื่อลดช่องว่างเกินหลังสัญลักษณ์ Sigma (Σ)
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
plt.subplot(211)
plt.text(0.4, 0.4, r'$\sum_{n=1}^{\infty}\; \frac{-e^{i\pi}}{2^n}!\left [a^2+\delta ^2- \frac{\pi}{2} \right ]$', fontsize=16, color='r')
plt.title("With thick space (\;)")
plt.subplot(212)
plt.text(0.4, 0.4, r'$\sum_{n=1}^{\infty}\! \frac{-e^{i\pi}}{2^n}!\left [a^2+\delta ^2- \frac{\pi}{2} \right ]$', fontsize=16, color='r')
plt.title("With negative thin space (\!)")
plt.show()
ผลลัพธ์
บนสุด: ช่องว่างกว้างหลัง Σ | ล่าง: ช่องว่างแคบ/ติดกันหลัง Σ

สรุป
- ใช้
\!เพื่อลดช่องว่างที่มากเกินไป - ใช้ raw string (r'...') เพื่อให้ backslash ทำงานถูกต้อง
- ปรับได้ทีละจุด ไม่กระทบส่วนอื่นของสมการ