Skip to content

Commit 38111b6

Browse files
LaTeX: Inhibit breaks for rows with merged vertical cells
This inhibits breaking in rows with vertically merged cells per stack exchange [1]. Tested against longtable. [1] https://tex.stackexchange.com/questions/52100/%20longtable-multirow-problem-with-cline-and-nopagebreak#answer-52101
1 parent 3c85411 commit 38111b6

File tree

9 files changed

+635
-11
lines changed

9 files changed

+635
-11
lines changed

CHANGES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ Bugs fixed
3535
Patch by Günter Milde
3636
* LaTeX: Fix rendering for grid filled merged vertical cell.
3737
Patch by Tim Nordell
38+
* LaTeX: Fix overrun footer for certain cases of merged vertical table cells.
39+
Patch by Tim Nordell
3840
* #14207: Fix creating ``HTMLThemeFactory`` objects in third-party extensions.
3941
Patch by Adam Turner
4042
* #3099: LaTeX: PDF build crashes if a code-block contains more than

sphinx/texinputs/sphinxlatextables.sty

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@
776776
\leaders\hrule\@height\arrayrulewidth\hfill}%
777777
\cr
778778
% the last one will need to be compensated, this is job of \sphinxclines
779-
\noalign{\vskip-\arrayrulewidth}%
779+
\noalign{\nobreak\vskip-\arrayrulewidth}%
780780
}
781781
\def\spx@table@fixvlinejoin{%
782782
{\CT@arc@ % this is the color command set up by \arrayrulecolor
@@ -800,7 +800,7 @@
800800
\hfill
801801
\spx@table@fixvlinejoin
802802
\cr
803-
\noalign{\vskip-\arrayrulewidth}%
803+
\noalign{\nobreak\vskip-\arrayrulewidth}%
804804
}
805805
% This "fixclines" is also needed if no \sphinxcline emitted and is useful
806806
% even in extreme case with no \sphinxvlinecrossing either, to give correct
@@ -819,6 +819,7 @@
819819
\spx@table@fixvlinejoin% fill small gap at right-bordered table
820820
\cr
821821
% this final one does NO \vskip-\arrayrulewidth... that's the whole point
822+
\noalign{\nobreak}%
822823
}
823824
%%%% end of \cline workarounds
824825

sphinx/writers/latex.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1307,15 +1307,16 @@ def visit_row(self, node: Element) -> None:
13071307

13081308
def depart_row(self, node: Element) -> None:
13091309
assert self.table is not None
1310-
self.body.append(r'\\' + CR)
13111310
cells = [self.table.cell(self.table.row, i) for i in range(self.table.colcount)]
13121311
underlined = [
13131312
cell.row + cell.height == self.table.row + 1 # type: ignore[union-attr]
13141313
for cell in cells
13151314
]
13161315
if all(underlined):
1316+
self.body.append(r'\\' + CR)
13171317
self.body.append(r'\sphinxhline')
13181318
else:
1319+
self.body.append(r'\\*' + CR)
13191320
i = 0
13201321
underlined.extend([False]) # sentinel
13211322
if underlined[0] is False:

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@
5252
\sphinxbeforeendvarwidth
5353
\end{varwidth}%
5454
}%
55-
\\
55+
\\*
5656
\sphinxvlinecrossing{1}\sphinxcline{3-3}\sphinxvlinecrossing{4}\sphinxfixclines{5}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxmultirow{2}{6}{%
5757
\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
5858
\sphinxAtStartPar
5959
cell2\sphinxhyphen{}3
6060
\sphinxbeforeendvarwidth
6161
\end{varwidth}%
6262
}%
63-
&\sphinxtablestrut{4}&\sphinxtablestrut{5}\\
63+
&\sphinxtablestrut{4}&\sphinxtablestrut{5}\\*
6464
\sphinxvlinecrossing{1}\sphinxvlinecrossing{2}\sphinxvlinecrossing{3}\sphinxcline{5-5}\sphinxfixclines{5}\sphinxtablestrut{1}&\sphinxtablestrut{2}&\sphinxtablestrut{6}&\sphinxtablestrut{4}&\begin{varwidth}[t]{\sphinxcolwidth{1}{5}}
6565
\sphinxAtStartPar
6666
cell3\sphinxhyphen{}5

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
cell1\sphinxhyphen{}3
4141
\sphinxbeforeendvarwidth
4242
\end{varwidth}%
43-
\\
43+
\\*
4444
\sphinxcline{1-1}\sphinxcline{3-3}\sphinxfixclines{3}\sphinxmultirow{2}{7}{%
4545
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
4646
\sphinxAtStartPar
@@ -53,7 +53,7 @@
5353
cell2\sphinxhyphen{}3
5454
\sphinxbeforeendvarwidth
5555
\end{varwidth}%
56-
\\
56+
\\*
5757
\sphinxcline{2-3}\sphinxfixclines{3}\sphinxtablestrut{7}&\sphinxstartmulticolumn{2}%
5858
\sphinxmultirow{2}{9}{%
5959
\begin{varwidth}[t]{\sphinxcolwidth{2}{3}}
@@ -66,7 +66,7 @@
6666
\end{varwidth}%
6767
}%
6868
\sphinxstopmulticolumn
69-
\\
69+
\\*
7070
\sphinxcline{1-1}\sphinxfixclines{3}\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
7171
\sphinxAtStartPar
7272
cell4\sphinxhyphen{}1

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
cell1\sphinxhyphen{}3
4141
\sphinxbeforeendvarwidth
4242
\end{varwidth}%
43-
\\
43+
\\*
4444
\sphinxcline{1-1}\sphinxcline{3-3}\sphinxfixclines{3}\sphinxmultirow{2}{7}{%
4545
\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
4646
\sphinxAtStartPar
@@ -53,7 +53,7 @@
5353
cell2\sphinxhyphen{}3
5454
\sphinxbeforeendvarwidth
5555
\end{varwidth}%
56-
\\
56+
\\*
5757
\sphinxcline{2-3}\sphinxfixclines{3}\sphinxtablestrut{7}&\sphinxstartmulticolumn{2}%
5858
\sphinxmultirow{2}{9}{%
5959
\begin{varwidth}[t]{\sphinxcolwidth{2}{3}}
@@ -66,7 +66,7 @@
6666
\end{varwidth}%
6767
}%
6868
\sphinxstopmulticolumn
69-
\\
69+
\\*
7070
\sphinxcline{1-1}\sphinxfixclines{3}\begin{varwidth}[t]{\sphinxcolwidth{1}{3}}
7171
\sphinxAtStartPar
7272
cell4\sphinxhyphen{}1

0 commit comments

Comments
 (0)