Latex bugs
State: closed

- [x] closes #19981 and 
closes #18669 
- [x] tests added / passed (see `test_to_latex.py`)
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [ ] whatsnew entry


Labels:
name: Output-Formatting
description: __repr__ of pandas objects, to_string
name: IO LaTeX
description: to_latex

Comments:
Also, after going through some of the other Latex-related bugs, I found [this discussion](https://github.com/pandas-dev/pandas/issues/13203#issuecomment-219744505) about refactoring `to_latex` to use `Styler`. @TomAugspurger, do you think that still makes sense?
Hi @shangyian, 
I came across this because I've also been looking at some to_latex bugs and have a PR open: https://github.com/pandas-dev/pandas/pull/19910

As part of the discussion I also realised that what you've renamed ``_rebuild_multi_index()`` could be much cleaner. I had a go at this here https://github.com/tomneep/pandas/blob/to_latex_nan_fix_alternative/pandas/io/formats/format.py#L905 and think it really helps. I think it also addresses #19981  (as well as fixing a couple of other bugs). So maybe that is a potential option. 

I have a question about one of your new tests, ``test_to_latex_multiindex_non_string``, I'd expect the header to be `0 & 1 &    \\` but in your test you have `{} & 1 &    \\`. Am I missing something?
@jreback - I did a preliminary PR to move the different formatters to separate files here: https://github.com/pandas-dev/pandas/pull/20051. Let me know what you think. 
@tomneep - Good catch on the test - not sure why I thought that made sense! As for the multi-indexing portion of the method, yeah, it makes sense to rework that to be clearer. I didn't change much from the original code when I pulled it into `_rebuild_multi_index`. 
ok let's rebase this and see where we are
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20032?src=pr&el=h1) Report
> Merging [#20032](https://codecov.io/gh/pandas-dev/pandas/pull/20032?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/92c29106d651c2690878827b07c29d88403c6f23?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/20032/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/20032?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #20032      +/-   ##
==========================================
- Coverage   91.77%   91.77%   -0.01%     
==========================================
  Files         152      152              
  Lines       49181    49200      +19     
==========================================
+ Hits        45138    45155      +17     
- Misses       4043     4045       +2
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.16% <100%> (-0.01%)` | :arrow_down: |
| #single | `41.83% <0%> (-0.02%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/20032?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/io/formats/latex.py](https://codecov.io/gh/pandas-dev/pandas/pull/20032/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2Zvcm1hdHMvbGF0ZXgucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [pandas/util/testing.py](https://codecov.io/gh/pandas-dev/pandas/pull/20032/diff?src=pr&el=tree#diff-cGFuZGFzL3V0aWwvdGVzdGluZy5weQ==) | `83.74% <0%> (-0.21%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20032?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/20032?src=pr&el=footer). Last update [92c2910...32df285](https://codecov.io/gh/pandas-dev/pandas/pull/20032?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Rebased and added some comments. 
Not sure if best to do this here, but we discussed combining `get_level_lengths` and `_get_level_lengths` in `formats.style` and I just did that now. 
Hello @shangyian! Thanks for updating the PR.

















Cheers ! There are no PEP8 issues in this Pull Request. :beers: 

##### Comment last updated on March 15, 2018 at 14:20 Hours UTC
can you rebase / fixup
closing as stale. if you'd like to continue pls ping.