Skip to content

Honor t/b in rgroup_sep for LaTeX output - #125

Open
soodoku wants to merge 1 commit into
py-econometrics:mainfrom
finite-sample:fix/tex-rgroup-sep
Open

soodoku wants to merge 1 commit into
py-econometrics:mainfrom
finite-sample:fix/tex-rgroup-sep

Conversation

@soodoku

@soodoku soodoku commented Nov 8, 2026

Copy link
Copy Markdown

What problem do you want to solve?

The rgroup_sep docs say "t" draws a line above each row group, "b" a line below, and "tb" both. Typst, Word and HTML output follow that. LaTeX output is the same for all three:

import pandas as pd
import maketables as mt

idx = pd.MultiIndex.from_tuples([("G1", "a"), ("G1", "b"), ("G2", "c"), ("G2", "d")])
df = pd.DataFrame({"(1)": ["1", "2", "3", "4"]}, index=idx)
for sep in ["tb", "t", "b", ""]:
    print(repr(sep), mt.MTable(df, rgroup_sep=sep).make("tex").count("\\midrule"))
# main: 2 2 2 1  (header rule + one rule between groups, whatever the letters)

Rule placement in the body (RULE = \midrule, \addlinespace omitted):

rgroup_sep main this PR (= Typst)
"tb" G1 a b RULE G2 c d G1 RULE a b RULE G2 RULE c d
"t" G1 a b RULE G2 c d G1 a b RULE G2 c d (unchanged)
"b" G1 a b RULE G2 c d G1 RULE a b G2 RULE c d
"" G1 a b G2 c d unchanged

Fix

This matches _output_typst:

  • t: the \midrule between groups (above every group but the first, where the header rule already sits) is drawn only when "t" is in rgroup_sep. rgroup_addlinespace around it is unchanged.
  • b: a \midrule directly below each displayed row-group name, including the first.

No rule is added for b when rgroup_display=False, which matches Word and HTML. Typst draws it even then, so with hidden names under the default "tb" it shows a rule at the top of the first data row of the first group, right under the header rule. That is why ETable output, which hides group names, is unchanged.

Behaviour change to flag: with the default "tb" and visible group names (DTable(byrow=...), a grouped MTable), LaTeX output now has a rule under each group name, as the default Typst/Word/HTML output already does. No existing snapshot covers that case, so no snapshot changes.

Tests

test_tex_rgroup_sep_places_rules_like_typst (in tests/api/test_mtable_outputs.py) is parametrized over "tb", "t", "b" and "". It checks the sequence of rules and rows in the LaTeX body, and checks that the number of rules equals the number of row-group table.hlines in the Typst output for the same table. 2 of the 4 cases ("tb", "b") fail on main, and all 4 pass with the fix. The "t" and "" cases are guards. The four variants also compile with pdflatex. Full suite: 502 passed, and all 135 snapshots are unchanged. pre-commit and ty are clean.

Open question

If the rule under the group name should not become the LaTeX default, the alternative is to change DEFAULT_RGROUP_SEP to "t". That keeps today's LaTeX look, but it changes the default Typst/Word/HTML rendering instead.

🤖 Generated with Claude Code

Problem: rgroup_sep is documented as "t" = line above each row group,
"b" = line below, "tb" = both. Typst, Word and HTML output follow that,
but LaTeX output was identical for "tb", "t" and "b": one \midrule
between consecutive row groups.

Cause: _output_tex only checked rgroup_sep != "".

Fix: draw the \midrule between groups only when "t" is in rgroup_sep
(above every group but the first, as in Typst), and add a \midrule
directly below each displayed row-group name when "b" is in rgroup_sep.
With the default "tb" and visible group names this adds a rule under
each name, matching the default Typst rendering.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant