Skip to content

Commit 6a6a770

Browse files
committed
Move \rownum reset away from longtable template into afterendhook
This is better not to overload our template. Besides it makes it easier for user to use another longtable template.
1 parent 866692d commit 6a6a770

11 files changed

+21
-18
lines changed

sphinx/templates/latex/longtable.tex_t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
\sphinxmidrule
5454
<% endif -%>
5555
\endhead
56-
\noalign{\global\rownum2 }%
56+
5757
\sphinxbottomrule
5858
\multicolumn{<%= table.colcount %>}{r}{\sphinxnorowcolor
5959
\makebox[0pt][r]{\sphinxtablecontinued{<%= _('continues on next page') %>}}%

sphinx/texinputs/sphinxlatextables.sty

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,10 @@
892892
\def\spx@table@resetcolortbl{%
893893
\sphinxrowcolorOFF
894894
\spx@table@reset@CTeverycr
895+
% this last bit is done in order for the \sphinxbottomrule from the "foot"
896+
% longtable template to be able to use same code as the \sphinxbottomrule
897+
% at end of table body; see \sphinxbooktabsspecialbottomrule code
898+
\global\rownum\z@
895899
}
896900
\def\spx@table@reset@CTeverycr{%
897901
% we should probably be more cautious and not hard-code here the colortbl
@@ -1174,13 +1178,12 @@ local use of booktabs table style}%
11741178
% execute again the colour selection code, but this is not too complicated.
11751179
% What is annoying though is that \sphinxbottomrule in the longtable context
11761180
% appears both in the "foot" part and after the last body row. For the first
1177-
% occurrence the \rownum has not been reset and could be arbitrary. So we had
1178-
% to set it to "2" in the longtable templates :-(. Not "0" in order to avoid
1179-
% \sphinxSwitchCaseRowColor having to know how to handle negative inputs,
1180-
% although the Sphinx definition has no issue with that. (there is no easy
1181-
% official way from longtable to know the macro is expanded in a "foot" box).
1182-
% So 2-1=1 and in longtable the colour will always be the "Odd" one, except at
1183-
% very end of longtable, where it will match colour of the last row.
1181+
% occurrence the \rownum could be arbitrary if it had not been reset by each
1182+
% table using it via the \sphinxtableafterendhook (see above). This avoids
1183+
% having to modify the longtable template. But as \rownum is thus 0 in the
1184+
% "foot", the \sphinxSwitchCaseRowColor has to know how to handle negative
1185+
% inputs (in fact the -1 value), the Sphinx definition has no issue with that
1186+
% but any redefinition must be aware of this constraint.
11841187
\def\sphinxbooktabsspecialbottomrule{%
11851188
\noalign{\global\let\spx@@saved@CT@arc@\CT@arc@
11861189
\sphinxSwitchCaseRowColor{\numexpr\rownum-\@ne\relax}%

tests/roots/test-latex-table/expects/longtable.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
\\
3030
\sphinxmidrule
3131
\endhead
32-
\noalign{\global\rownum2 }%
32+
3333
\sphinxbottomrule
3434
\multicolumn{2}{r}{\sphinxnorowcolor
3535
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%

tests/roots/test-latex-table/expects/longtable_having_align.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
\\
2929
\sphinxmidrule
3030
\endhead
31-
\noalign{\global\rownum2 }%
31+
3232
\sphinxbottomrule
3333
\multicolumn{2}{r}{\sphinxnorowcolor
3434
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%

tests/roots/test-latex-table/expects/longtable_having_caption.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
\\
3131
\sphinxmidrule
3232
\endhead
33-
\noalign{\global\rownum2 }%
33+
3434
\sphinxbottomrule
3535
\multicolumn{2}{r}{\sphinxnorowcolor
3636
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%

tests/roots/test-latex-table/expects/longtable_having_problematic_cell.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
\\
2929
\sphinxmidrule
3030
\endhead
31-
\noalign{\global\rownum2 }%
31+
3232
\sphinxbottomrule
3333
\multicolumn{2}{r}{\sphinxnorowcolor
3434
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%

tests/roots/test-latex-table/expects/longtable_having_stub_columns_and_problematic_cell.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
\\
3535
\sphinxmidrule
3636
\endhead
37-
\noalign{\global\rownum2 }%
37+
3838
\sphinxbottomrule
3939
\multicolumn{3}{r}{\sphinxnorowcolor
4040
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%

tests/roots/test-latex-table/expects/longtable_having_verbatim.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
\\
2929
\sphinxmidrule
3030
\endhead
31-
\noalign{\global\rownum2 }%
31+
3232
\sphinxbottomrule
3333
\multicolumn{2}{r}{\sphinxnorowcolor
3434
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%

tests/roots/test-latex-table/expects/longtable_having_widths.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
\sphinxatlongtablestart
55
\sphinxthistablewithglobalstyle
66
\begin{longtable}[c]{|\X{30}{100}|\X{70}{100}|}
7-
\noalign{\phantomsection\label{\detokenize{longtable:namedlongtable}}\label{\detokenize{longtable:mylongtable}}}%
7+
88
\sphinxtoprule
99
\sphinxstyletheadfamily
1010
\sphinxAtStartPar
@@ -29,7 +29,7 @@
2929
\\
3030
\sphinxmidrule
3131
\endhead
32-
\noalign{\global\rownum2 }%
32+
3333
\sphinxbottomrule
3434
\multicolumn{2}{r}{\sphinxnorowcolor
3535
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%

tests/roots/test-latex-table/expects/longtable_having_widths_and_problematic_cell.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
\\
2929
\sphinxmidrule
3030
\endhead
31-
\noalign{\global\rownum2 }%
31+
3232
\sphinxbottomrule
3333
\multicolumn{2}{r}{\sphinxnorowcolor
3434
\makebox[0pt][r]{\sphinxtablecontinued{continues on next page}}%

0 commit comments

Comments
 (0)