diff --git a/doc/source/whatsnew/v1.4.0.rst b/doc/source/whatsnew/v1.4.0.rst index 7c03e10c86bd4..8c85ddd7f55f7 100644 --- a/doc/source/whatsnew/v1.4.0.rst +++ b/doc/source/whatsnew/v1.4.0.rst @@ -105,6 +105,7 @@ There are also some LaTeX specific enhancements: - :meth:`.Styler.to_latex` introduces keyword argument ``environment``, which also allows a specific "longtable" entry through a separate jinja2 template (:issue:`41866`). - Naive sparsification is now possible for LaTeX without the necessity of including the multirow package (:issue:`43369`) + - *cline* support has been added for MultiIndex row sparsification through a keyword argument (:issue:`45138`) .. _whatsnew_140.enhancements.pyarrow_csv_engine: diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 2e74ac93b1ced..29c1e35dbb546 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -494,6 +494,7 @@ def to_latex( position: str | None = None, position_float: str | None = None, hrules: bool | None = None, + clines: str | None = None, label: str | None = None, caption: str | tuple | None = None, sparse_index: bool | None = None, @@ -542,6 +543,22 @@ def to_latex( Defaults to ``pandas.options.styler.latex.hrules``, which is `False`. .. versionchanged:: 1.4.0 + clines : str, optional + Use to control adding \\cline commands for the index labels separation. + Possible values are: + + - `None`: no cline commands are added (default). + - `"all;data"`: a cline is added for every index value extending the + width of the table, including data entries. + - `"all;index"`: as above with lines extending only the width of the + index entries. + - `"skip-last;data"`: a cline is added for each index value except the + last level (which is never sparsified), extending the widtn of the + table. + - `"skip-last;index"`: as above with lines extending only the width of the + index entries. + + .. versionadded:: 1.4.0 label : str, optional The LaTeX label included as: \\label{