BUG: Issue with to_latex and MultiIndex column format. GH8336
State: closed

closes #8336 

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}

```


Labels:
name: Output-Formatting
description: __repr__ of pandas objects, to_string
name: MultiIndex

Comments:
This is my first PR on this project,  please let me know if there are format issues,  or other things I need to do.  I've looked through [CONTRIBUTING.md](https://github.com/pydata/pandas/blob/master/CONTRIBUTING.md) and done my best.

Cheers!

The first thing somebody will tell you is that you need to add some tests for your change.

@kotfic also, pls post a before and after rendered version of this

Thanks for the feedback,  I know it can be a pain bringing up new contributors. 

![tmp](https://cloud.githubusercontent.com/assets/669959/4998108/27d3547c-69a3-11e4-8eb6-c3dd30a87918.png)

I'll fix the test later this evening!
Thanks!
/Chris

@kotfic can you rebase this and we can get this in.

@jreback Hi,  sorry I lost track of this,  I have rebased,  is there something I need to do to update the pull-request?

@kotfic First, can you try to rebase again? As something went wrong there, making it very difficult to review.

Normally you can just do:

```
git fetch upstream
git rebase upstream/master
git push -f
```

and it should be OK.

Secondly, some other needed updates:
- Can you add a test for this? 
- Can you add a small release note in doc/source/whatsnew/v0.16.1.txt?

If you need any help, just ask here! (or at https://gitter.im/pydata/pandas)

cc @hayd 

@kotfic can you rebase on master, and squash your commits, 
see [here](http://pandas-docs.github.io/pandas-docs-travis/contributing.html) for help

closing as stale, but if you would like to reopen and fixup pls do.