diff --git a/doc/source/user_guide/options.rst b/doc/source/user_guide/options.rst index 59319fda8045c..a65bb774b9df8 100644 --- a/doc/source/user_guide/options.rst +++ b/doc/source/user_guide/options.rst @@ -512,6 +512,7 @@ styler.latex.multicol_align r Alignment of headers in a m styler.latex.multirow_align c Alignment of index labels in a merged row due to sparsification. Can be in {"c", "t", "b"}. styler.latex.environment None If given will replace the default ``\\begin{table}`` environment. If "longtable" is specified this will render with a specific "longtable" template with longtable features. +styler.latex.hrules False If set to True will render ``\\toprule``, ``\\midrule``, and ``\bottomrule`` by default. ======================================= ============ ================================== diff --git a/pandas/core/config_init.py b/pandas/core/config_init.py index 3f7363836acdb..0081f8cd074b6 100644 --- a/pandas/core/config_init.py +++ b/pandas/core/config_init.py @@ -823,6 +823,11 @@ def register_converter_cb(key): rules, e.g. "\|r" will draw a rule on the left side of right aligned merged cells. """ +styler_hrules = """ +: bool + Whether to add horizontal rules on top and bottom and below the headers. +""" + styler_environment = """ : str The environment to replace ``\\begin{table}``. If "longtable" is used results @@ -929,6 +934,8 @@ def register_converter_cb(key): validator=is_one_of_factory(val_mca), ) + cf.register_option("latex.hrules", False, styler_hrules, validator=is_bool) + cf.register_option( "latex.environment", None, diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 9bac0f4fb09f5..9f0806c9fda43 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -468,7 +468,7 @@ def to_latex( column_format: str | None = None, position: str | None = None, position_float: str | None = None, - hrules: bool = False, + hrules: bool | None = None, label: str | None = None, caption: str | tuple | None = None, sparse_index: bool | None = None, @@ -488,7 +488,7 @@ def to_latex( Parameters ---------- buf : str, Path, or StringIO-like, optional, default None - Buffer to write to. If ``None``, the output is returned as a string. + Buffer to write to. If `None`, the output is returned as a string. column_format : str, optional The LaTeX column specification placed in location: @@ -509,9 +509,12 @@ def to_latex( \\ Cannot be used if ``environment`` is "longtable". - hrules : bool, default False + hrules : bool Set to `True` to add \\toprule, \\midrule and \\bottomrule from the {booktabs} LaTeX package. + Defaults to ``pandas.options.styler.latex.hrules``, which is `False`. + + .. versionchanged:: 1.4.0 label : str, optional The LaTeX label included as: \\label{