Pandas version checks
-
[X] I have checked that this issue has not already been reported.
-
[X] I have confirmed this bug exists on the latest version of pandas.
-
[ ] I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
import pandas as pd
print(pd.Series([10, 12.4], index=['spam', 'eggs in %']).reset_index().to_latex())
>>>
\begin{tabular}{llr}
\toprule
& index & 0 \\
\midrule
0 & spam & 10.000000 \\
1 & eggs in % & 12.400000 \\
\bottomrule
\end{tabular}
Issue Description
The %
sign is the comment sign in latex. When specified in columns or the index it must always be escaped, that is \%
instead of just %
in the output produced by to_latex()
Expected Behavior
The %
is always exported as \%
in latex
Installed Versions
INSTALLED VERSIONS
------------------
commit : 37ea63d540fd27274cad6585082c91b1283f963d
python : 3.11.3.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.19044
machine : AMD64
processor : Intel64 Family 6 Model 140 Stepping 1, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : fr_FR.cp1252
pandas : 2.0.1
numpy : 1.24.3
pytz : 2022.7
dateutil : 2.8.2
setuptools : 66.0.0
pip : 23.0.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.9.2
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.1.2
IPython : 8.12.0
pandas_datareader: None
bs4 : 4.12.2
bottleneck : 1.3.5
brotli :
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : 3.7.1
numba : None
numexpr : 2.8.4
odfpy : None
openpyxl : 3.0.10
pandas_gbq : None
pyarrow : 11.0.0
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : 1.10.1
snappy : None
sqlalchemy : None
tables : None
tabulate : 0.8.10
xarray : None
xlrd : None
zstandard : None
tzdata : 2023.3
qtpy : 2.2.0
pyqt5 : None
Comment From: arnaudlegout
My mistake, I found the parameter escape=True
in to_latex
. Could have been better to have it True by default.