pydata/pandas — pull request #8784 by kotfic (2014-11-11 13:52:55+00:00)
Title: BUG: Issue with to_latex and MultiIndex column format. GH8336

This is a potential resolution to GH8336 It borrows the same code flow from _get_formatted_index in
pandas.core.format

```python
import pandas as pd
pd.show_versions()

df = pd.DataFrame({
"A": [191, 191, 193, 193, 193],
"B": [1, 1, 2, 2, 3],
"C": ["foo", "foo", "foo", "foo", "foo"],
"D": ["bar", "bar", "bar", "bar", "bar"]})

print "\nOutput:"
print df.set_index(["A", "B"]).to_latex()
```

```latex
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.8.final.0
python-bits: 64
OS: Linux
OS-release: 3.17.2-1-ARCH
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: C

pandas: 0.15.1
nose: 1.3.4
Cython: 0.21.1
numpy: 1.9.1
scipy: 0.14.0
statsmodels: 0.6.0
IPython: 2.3.0
sphinx: 1.2.3
patsy: 0.3.0
dateutil: 2.2
pytz: 2014.9
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.4.0
openpyxl: 2.1.1
xlrd: 0.9.3
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.3.2
html5lib: None
httplib2: 0.9
apiclient: None
rpy2: None
sqlalchemy: 0.9.8
pymysql: None
psycopg2: None

Output:
\begin{tabular}{llll}
\toprule
& & C & D \\
\midrule
191 & 1 & & \\
193 & 2 & foo & bar \\
\bottomrule
\end{tabular}
```

After PR
```latex
INSTALLED VERSIONS
------------------
commit: None
python: 2.7.8.final.0
python-bits: 64
OS: Linux
OS-release: 3.17.2-1-ARCH
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: C

pandas: 0.15.1-18-g81c8a5f
nose: None
Cython: None
numpy: 1.9.1
scipy: None
statsmodels: None
IPython: 2.3.0
sphinx: None
patsy: None
dateutil: 2.2
pytz: 2014.9
bottleneck: None
tables: None
numexpr: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
httplib2: None
apiclient: None
rpy2: None
sqlalchemy: None
pymysql: None
psycopg2: None

Output:
\begin{tabular}{llll}
\toprule
& & C & D \\
\midrule
191 & 1 & & \\
& 1 & foo & bar \\
193 & 2 & foo & bar \\
& 2 & foo & bar \\
& 3 & foo & bar \\
\bottomrule
\end{tabular}

```