DOC: Fix to_latex docstring.
State: closed

- [x] tests added / passed
- [x] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`

Fix the DataFrame.to_latex docstring to match `scripts/validate_docstrings.py` as explained in #22459  and add an example.

The docstring was previously in a variable that was only used in to_latex. I put it in the method docstring instead. The `@Substitution` wasn't matching anything, I suspect this dates back to the common docstring in `io/formats/format.py`.


Labels:
name: Docs
name: IO LaTeX
description: to_latex

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22516?src=pr&el=h1) Report
> Merging [#22516](https://codecov.io/gh/pandas-dev/pandas/pull/22516?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/fa47b8d95e4752d2687b0aee5942dcbb34f61362?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/22516/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/22516?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #22516      +/-   ##
==========================================
- Coverage   92.04%   92.04%   -0.01%     
==========================================
  Files         169      169              
  Lines       50787    50784       -3     
==========================================
- Hits        46746    46743       -3     
  Misses       4041     4041
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.45% <100%> (-0.01%)` | :arrow_down: |
| #single | `42.29% <100%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/22516?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/generic.py](https://codecov.io/gh/pandas-dev/pandas/pull/22516/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZ2VuZXJpYy5weQ==) | `96.43% <100%> (-0.01%)` | :arrow_down: |
| [pandas/core/indexes/multi.py](https://codecov.io/gh/pandas-dev/pandas/pull/22516/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9tdWx0aS5weQ==) | `95.41% <0%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/22516/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.2% <0%> (ø)` | :arrow_up: |
| [pandas/core/indexes/base.py](https://codecov.io/gh/pandas-dev/pandas/pull/22516/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9iYXNlLnB5) | `96.45% <0%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/22516?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/22516?src=pr&el=footer). Last update [fa47b8d...c64fb5d](https://codecov.io/gh/pandas-dev/pandas/pull/22516?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

Hello @Moisan! Thanks for updating the PR.

 - There are no PEP8 issues in the file [`pandas/core/generic.py`](https://github.com/Moisan/pandas/blob/052a32f3bca07c47a17d845c62178efb2ad16c69/pandas/core/generic.py) !


`./scripts/validate_docstrings.py pandas.DataFrame.to_latex` returns that everything is correct.
That's an error in the script them. Can you post the output of the script to see how the docstring is veing rendered, and see if it helps to see what's wrong with the script.

And after that fix the docstring, so the first line (short summary) fits in a single line, as described here: https://pandas.pydata.org/pandas-docs/stable/contributing_docstring.html
Here is [the output](https://gist.github.com/Moisan/5b349fddeea6f7ed83987673f7bde5de). I can open an issue regarding the bug of `scripts/validate_docstrings.py`.
thanks @Moisan