1%% TABLES (WITH SUPPORT FOR MERGED CELLS OF GENERAL CONTENTS)
2%
3% change this info string if making any custom modification
4\ProvidesFile{sphinxlatextables.sty}[2021/01/27 tables]%
5
6% Provides support for this output mark-up from Sphinx latex writer
7% and table templates:
8%
9% - the tabulary and longtable environments from the eponymous packages
10% - the varwidth environment
11% - the >{} etc mark-up possible in tabularcolumns is from array package
12%     which is loaded by longtable and tabulary
13% - \X, \Y, T column types; others (L, C, R, J) are from tabulary package
14% - \sphinxaftertopcaption
15% - \sphinxatlongtableend
16% - \sphinxatlongtablestart
17% - \sphinxattableend
18% - \sphinxattablestart
19% - \sphinxcapstartof
20% - \sphinxcolwidth
21% - \sphinxlongtablecapskipadjust
22% - \sphinxmultirow
23% - \sphinxstartmulticolumn
24% - \sphinxstopmulticolumn
25% - \sphinxtablestrut
26% - \sphinxthecaptionisattop
27% - \sphinxthelongtablecaptionisattop
28%
29% Executes \RequirePackage for:
30%
31% - tabulary
32% - longtable
33% - varwidth
34%
35% Extends tabulary and longtable via patches and custom macros to support
36% merged cells possibly containing code-blocks in complex tables
37
38\RequirePackage{tabulary}
39% tabulary has a bug with its re-definition of \multicolumn in its first pass
40% which is not \long. But now Sphinx does not use LaTeX's \multicolumn but its
41% own macro. Hence we don't even need to patch tabulary. See
42% sphinxpackagemulticell.sty
43% X or S (Sphinx) may have meanings if some table package is loaded hence
44% \X was chosen to avoid possibility of conflict
45\newcolumntype{\X}[2]{p{\dimexpr
46      (\linewidth-\arrayrulewidth)*#1/#2-\tw@\tabcolsep-\arrayrulewidth\relax}}
47\newcolumntype{\Y}[1]{p{\dimexpr
48      #1\dimexpr\linewidth-\arrayrulewidth\relax-\tw@\tabcolsep-\arrayrulewidth\relax}}
49% using here T (for Tabulary) feels less of a problem than the X could be
50\newcolumntype{T}{J}%
51% For tables allowing pagebreaks
52\RequirePackage{longtable}
53% User interface to set-up whitespace before and after tables:
54\newcommand*\sphinxtablepre {0pt}%
55\newcommand*\sphinxtablepost{\medskipamount}%
56% Space from caption baseline to top of table or frame of literal-block
57\newcommand*\sphinxbelowcaptionspace{.5\sphinxbaselineskip}%
58% as one can not use \baselineskip from inside longtable (it is zero there)
59% we need \sphinxbaselineskip, which defaults to \baselineskip
60\def\sphinxbaselineskip{\baselineskip}%
61% The following is to ensure that, whether tabular(y) or longtable:
62% - if a caption is on top of table:
63%   a) the space between its last baseline and the top rule of table is
64%      exactly \sphinxbelowcaptionspace
65%   b) the space from last baseline of previous text to first baseline of
66%      caption is exactly \parskip+\baselineskip+ height of a strut.
67%   c) the caption text will wrap at width \LTcapwidth (4in)
68% - make sure this works also if "caption" package is loaded by user
69%   (with its width or margin option taking place of \LTcapwidth role)
70% TODO: obtain same for caption of literal block: a) & c) DONE, b) TO BE DONE
71%
72% To modify space below such top caption, adjust \sphinxbelowcaptionspace
73% To add or remove space above such top caption, adjust \sphinxtablepre:
74%   notice that \abovecaptionskip, \belowcaptionskip, \LTpre are **ignored**
75% A. Table with longtable
76\def\sphinxatlongtablestart
77   {\par
78    \vskip\parskip
79    \vskip\dimexpr\sphinxtablepre\relax % adjust vertical position
80    \vbox{}% get correct baseline from above
81    \LTpre\z@skip\LTpost\z@skip % set to zero longtable's own skips
82    \edef\sphinxbaselineskip{\dimexpr\the\dimexpr\baselineskip\relax\relax}%
83   }%
84% Compatibility with caption package
85\def\sphinxthelongtablecaptionisattop{%
86    \spx@ifcaptionpackage{\noalign{\vskip-\belowcaptionskip}}{}%
87}%
88% Achieves exactly \sphinxbelowcaptionspace below longtable caption
89\def\sphinxlongtablecapskipadjust
90   {\dimexpr-\dp\strutbox
91            -\spx@ifcaptionpackage{\abovecaptionskip}{\sphinxbaselineskip}%
92            +\sphinxbelowcaptionspace\relax}%
93\def\sphinxatlongtableend{\@nobreakfalse % latex3/latex2e#173
94    \prevdepth\z@\vskip\sphinxtablepost\relax}%
95% B. Table with tabular or tabulary
96\def\sphinxattablestart{\par\vskip\dimexpr\sphinxtablepre\relax}%
97\let\sphinxattableend\sphinxatlongtableend
98% This is used by tabular and tabulary templates
99\newcommand*\sphinxcapstartof[1]{%
100   \vskip\parskip
101   \vbox{}% force baselineskip for good positioning by capstart of hyperanchor
102   % hyperref puts the anchor 6pt above this baseline; in case of caption
103   % this baseline will be \ht\strutbox above first baseline of caption
104   \def\@captype{#1}%
105   \capstart
106% move back vertically, as tabular (or its caption) will compensate
107   \vskip-\baselineskip\vskip-\parskip
108}%
109\def\sphinxthecaptionisattop{% locate it after \sphinxcapstartof
110    \spx@ifcaptionpackage
111      {\caption@setposition{t}%
112       \vskip\baselineskip\vskip\parskip % undo those from \sphinxcapstartof
113       \vskip-\belowcaptionskip          % anticipate caption package skip
114       % caption package uses a \vbox, not a \vtop, so "single line" case
115       % gives different result from "multi-line" without this:
116       \nointerlineskip
117      }%
118      {}%
119}%
120\def\sphinxthecaptionisatbottom{% (not finalized; for template usage)
121    \spx@ifcaptionpackage{\caption@setposition{b}}{}%
122}%
123% The aim of \sphinxcaption is to apply to tabular(y) the maximal width
124% of caption as done by longtable
125\def\sphinxtablecapwidth{\LTcapwidth}%
126\newcommand\sphinxcaption{\@dblarg\spx@caption}%
127\long\def\spx@caption[#1]#2{%
128   \noindent\hb@xt@\linewidth{\hss
129      \vtop{\@tempdima\dimexpr\sphinxtablecapwidth\relax
130% don't exceed linewidth for the caption width
131            \ifdim\@tempdima>\linewidth\hsize\linewidth\else\hsize\@tempdima\fi
132% longtable ignores \abovecaptionskip/\belowcaptionskip, so do the same here
133            \abovecaptionskip\sphinxabovecaptionskip % \z@skip
134            \belowcaptionskip\sphinxbelowcaptionskip % \z@skip
135            \caption[{#1}]%
136               {\strut\ignorespaces#2\ifhmode\unskip\@finalstrut\strutbox\fi}%
137           }\hss}%
138   \par\prevdepth\dp\strutbox
139}%
140\def\sphinxabovecaptionskip{\z@skip}% Do not use! Flagged for removal
141\def\sphinxbelowcaptionskip{\z@skip}% Do not use! Flagged for removal
142% This wrapper of \abovecaptionskip is used in sphinxVerbatim for top
143% caption, and with another value in sphinxVerbatimintable
144% TODO: To unify space above caption of a code-block with the one above
145%       caption of a table/longtable, \abovecaptionskip must not be used
146%       This auxiliary will get renamed and receive a different meaning
147%       in future.
148\def\spx@abovecaptionskip{\abovecaptionskip}%
149% Achieve \sphinxbelowcaptionspace below a caption located above a tabular
150% or a tabulary
151\newcommand\sphinxaftertopcaption
152{%
153   \spx@ifcaptionpackage
154     {\par\prevdepth\dp\strutbox\nobreak\vskip-\abovecaptionskip}{\nobreak}%
155   \vskip\dimexpr\sphinxbelowcaptionspace\relax
156   \vskip-\baselineskip\vskip-\parskip
157}%
158% varwidth is crucial for our handling of general contents in merged cells
159\RequirePackage{varwidth}
160% but addition of a compatibility patch with hyperref is needed
161% (tested with varwidth v 0.92  Mar 2009)
162\AtBeginDocument {%
163    \let\@@vwid@Hy@raisedlink\Hy@raisedlink
164    \long\def\@vwid@Hy@raisedlink#1{\@vwid@wrap{\@@vwid@Hy@raisedlink{#1}}}%
165    \edef\@vwid@setup{%
166      \let\noexpand\Hy@raisedlink\noexpand\@vwid@Hy@raisedlink % HYPERREF !
167      \unexpanded\expandafter{\@vwid@setup}}%
168}%
169
170%%%%%%%%%%%%%%%%%%%%%
171% --- MULTICOLUMN ---
172% standard LaTeX's \multicolumn
173% 1. does not allow verbatim contents,
174% 2. interacts very poorly with tabulary.
175%
176% It is needed to write own macros for Sphinx: to allow code-blocks in merged
177% cells rendered by tabular/longtable, and to allow multi-column cells with
178% paragraphs to be taken into account sanely by tabulary algorithm for column
179% widths.
180%
181% This requires quite a bit of hacking. First, in Sphinx, the multi-column
182% contents will *always* be wrapped in a varwidth environment. The issue
183% becomes to pass it the correct target width. We must trick tabulary into
184% believing the multicolumn is simply separate columns, else tabulary does not
185% incorporate the contents in its algorithm. But then we must clear the
186% vertical rules...
187%
188% configuration of tabulary
189\setlength{\tymin}{3\fontcharwd\font`0 }% minimal width of "squeezed" columns
190\setlength{\tymax}{10000pt}% allow enough room for paragraphs to "compete"
191% we need access to tabulary's final computed width. \@tempdima is too volatile
192% to hope it has kept tabulary's value when \sphinxcolwidth needs it.
193\newdimen\sphinx@TY@tablewidth
194\def\tabulary{%
195  \def\TY@final{\sphinx@TY@tablewidth\@tempdima\tabular}%
196  \let\endTY@final\endtabular
197  \TY@tabular}%
198% next hack is needed only if user has set latex_use_latex_multicolumn to True:
199% it fixes tabulary's bug with \multicolumn defined "short" in first pass. (if
200% upstream tabulary adds a \long, our extra one causes no harm)
201\def\sphinx@tempa #1\def\multicolumn#2#3#4#5#6#7#8#9\sphinx@tempa
202   {\def\TY@tab{#1\long\def\multicolumn####1####2####3{\multispan####1\relax}#9}}%
203\expandafter\sphinx@tempa\TY@tab\sphinx@tempa
204%
205% TN. 1: as \omit is never executed, Sphinx multicolumn does not need to worry
206% like standard multicolumn about |l| vs l|. On the other hand it assumes
207% columns are separated by a | ... (if not it will add extraneous
208% \arrayrulewidth space for each column separation in its estimate of available
209% width).
210%
211% TN. 1b: as Sphinx multicolumn uses neither \omit nor \span, it can not
212% (easily) get rid of extra macros from >{...} or <{...} between columns. At
213% least, it has been made compatible with colortbl's \columncolor.
214%
215% TN. 2: tabulary's second pass is handled like tabular/longtable's single
216% pass, with the difference that we hacked \TY@final to set in
217% \sphinx@TY@tablewidth the final target width as computed by tabulary. This is
218% needed only to handle columns with a "horizontal" specifier: "p" type columns
219% (inclusive of tabulary's LJRC) holds the target column width in the
220% \linewidth dimension.
221%
222% TN. 3: use of \begin{sphinxmulticolumn}...\end{sphinxmulticolumn} mark-up
223% would need some hacking around the fact that groups can not span across table
224% cells (the code does inserts & tokens, see TN1b). It was decided to keep it
225% simple with \sphinxstartmulticolumn...\sphinxstopmulticolumn.
226%
227% MEMO about nesting: if sphinxmulticolumn is encountered in a nested tabular
228% inside a tabulary it will think to be at top level in the tabulary. But
229% Sphinx generates no nested tables, and if some LaTeX macro uses internally a
230% tabular this will not have a \sphinxstartmulticolumn within it!
231%
232\def\sphinxstartmulticolumn{%
233    \ifx\equation$% $ tabulary's first pass
234        \expandafter\sphinx@TYI@start@multicolumn
235    \else % either not tabulary or tabulary's second pass
236        \expandafter\sphinx@start@multicolumn
237    \fi
238}%
239\def\sphinxstopmulticolumn{%
240    \ifx\equation$% $ tabulary's first pass
241        \expandafter\sphinx@TYI@stop@multicolumn
242    \else % either not tabulary or tabulary's second pass
243        \ignorespaces
244    \fi
245}%
246\def\sphinx@TYI@start@multicolumn#1{%
247    % use \gdef always to avoid stack space build up
248    \gdef\sphinx@tempa{#1}\begingroup\setbox\z@\hbox\bgroup
249}%
250\def\sphinx@TYI@stop@multicolumn{\egroup % varwidth was used with \tymax
251    \xdef\sphinx@tempb{\the\dimexpr\wd\z@/\sphinx@tempa}% per column width
252    \endgroup
253    \expandafter\sphinx@TYI@multispan\expandafter{\sphinx@tempa}%
254}%
255\def\sphinx@TYI@multispan #1{%
256    \kern\sphinx@tempb\ignorespaces % the per column occupied width
257    \ifnum#1>\@ne % repeat, taking into account subtleties of TeX's & ...
258      \expandafter\sphinx@TYI@multispan@next\expandafter{\the\numexpr#1-\@ne\expandafter}%
259    \fi
260}%
261\def\sphinx@TYI@multispan@next{&\relax\sphinx@TYI@multispan}%
262%
263% Now the branch handling either the second pass of tabulary or the single pass
264% of tabular/longtable. This is the delicate part where we gather the
265% dimensions from the p columns either set-up by tabulary or by user p column
266% or Sphinx \X, \Y columns. The difficulty is that to get the said width, the
267% template must be inserted (other hacks would be horribly complicated except
268% if we rewrote crucial parts of LaTeX's \@array !) and we can not do
269% \omit\span like standard \multicolumn's easy approach. Thus we must cancel
270% the \vrule separators. Also, perhaps the column specifier is of the l, c, r
271% type, then we attempt an ad hoc rescue to give varwidth a reasonable target
272% width.
273\def\sphinx@start@multicolumn#1{%
274    \gdef\sphinx@multiwidth{0pt}\gdef\sphinx@tempa{#1}\sphinx@multispan{#1}%
275}%
276\def\sphinx@multispan #1{%
277    \ifnum#1=\@ne\expandafter\sphinx@multispan@end
278            \else\expandafter\sphinx@multispan@next
279    \fi {#1}%
280}%
281\def\sphinx@multispan@next #1{%
282    % trick to recognize L, C, R, J or p, m, b type columns
283    \ifdim\baselineskip>\z@
284       \gdef\sphinx@tempb{\linewidth}%
285    \else
286    % if in an l, r, c type column, try and hope for the best
287       \xdef\sphinx@tempb{\the\dimexpr(\ifx\TY@final\@undefined\linewidth\else
288            \sphinx@TY@tablewidth\fi-\arrayrulewidth)/\sphinx@tempa
289            -\tw@\tabcolsep-\arrayrulewidth\relax}%
290    \fi
291    \noindent\kern\sphinx@tempb\relax
292    \xdef\sphinx@multiwidth
293           {\the\dimexpr\sphinx@multiwidth+\sphinx@tempb+\tw@\tabcolsep+\arrayrulewidth}%
294    % hack the \vline and the colortbl macros
295    \sphinx@hack@vline\sphinx@hack@CT&\relax
296    % repeat
297    \expandafter\sphinx@multispan\expandafter{\the\numexpr#1-\@ne}%
298}%
299% packages like colortbl add group levels, we need to "climb back up" to be
300% able to hack the \vline and also the colortbl inserted tokens. This creates
301% empty space whether or not the columns were | separated:
302\def\sphinx@hack@vline{\ifnum\currentgrouptype=6\relax
303    \kern\arrayrulewidth\arrayrulewidth\z@\else\aftergroup\sphinx@hack@vline\fi}%
304\def\sphinx@hack@CT{\ifnum\currentgrouptype=6\relax
305    \let\CT@setup\sphinx@CT@setup\else\aftergroup\sphinx@hack@CT\fi}%
306% It turns out \CT@row@color is not expanded contrarily to \CT@column@color
307% during LaTeX+colortbl preamble preparation, hence it would be possible for
308% \sphinx@CT@setup to discard only the column color and choose to obey or not
309% row color and cell color. It would even be possible to propagate cell color
310% to row color for the duration of the Sphinx multicolumn... the (provisional?)
311% choice has been made to cancel the colortbl colours for the multicolumn
312% duration.
313\def\sphinx@CT@setup #1\endgroup{\endgroup}% hack to remove colour commands
314\def\sphinx@multispan@end#1{%
315    % first, trace back our steps horizontally
316    \noindent\kern-\dimexpr\sphinx@multiwidth\relax
317    % and now we set the final computed width for the varwidth environment
318    \ifdim\baselineskip>\z@
319       \xdef\sphinx@multiwidth{\the\dimexpr\sphinx@multiwidth+\linewidth}%
320    \else
321       \xdef\sphinx@multiwidth{\the\dimexpr\sphinx@multiwidth+
322         (\ifx\TY@final\@undefined\linewidth\else
323          \sphinx@TY@tablewidth\fi-\arrayrulewidth)/\sphinx@tempa
324          -\tw@\tabcolsep-\arrayrulewidth\relax}%
325    \fi
326    % we need to remove colour set-up also for last cell of the multi-column
327    \aftergroup\sphinx@hack@CT
328}%
329\newcommand*\sphinxcolwidth[2]{%
330  % this dimension will always be used for varwidth, and serves as maximum
331  % width when cells are merged either via multirow or multicolumn or both,
332  % as always their contents is wrapped in varwidth environment.
333  \ifnum#1>\@ne % multi-column (and possibly also multi-row)
334  % we wrote our own multicolumn code especially to handle that (and allow
335  % verbatim contents)
336   \ifx\equation$%$
337       \tymax % first pass of tabulary (cf MEMO above regarding nesting)
338   \else % the \@gobble thing is for compatibility with standard \multicolumn
339       \sphinx@multiwidth\@gobble{#1/#2}%
340   \fi
341  \else % single column multirow
342   \ifx\TY@final\@undefined % not a tabulary.
343    \ifdim\baselineskip>\z@
344        % in a p{..} type column, \linewidth is the target box width
345        \linewidth
346    \else
347        % l, c, r columns. Do our best.
348        \dimexpr(\linewidth-\arrayrulewidth)/#2-
349                \tw@\tabcolsep-\arrayrulewidth\relax
350    \fi
351   \else % in tabulary
352    \ifx\equation$%$% first pass
353        \tymax % it is set to a big value so that paragraphs can express themselves
354    \else
355     % second pass.
356     \ifdim\baselineskip>\z@
357         \linewidth % in a L, R, C, J column or a p, \X, \Y ...
358     \else
359         % we have hacked \TY@final to put in \sphinx@TY@tablewidth the table width
360         \dimexpr(\sphinx@TY@tablewidth-\arrayrulewidth)/#2-
361                 \tw@\tabcolsep-\arrayrulewidth\relax
362     \fi
363    \fi
364   \fi
365  \fi
366}%
367% fallback default in case user has set latex_use_latex_multicolumn to True:
368% \sphinxcolwidth will use this only inside LaTeX's standard \multicolumn
369\def\sphinx@multiwidth #1#2{\dimexpr % #1 to gobble the \@gobble (!)
370    (\ifx\TY@final\@undefined\linewidth\else\sphinx@TY@tablewidth\fi
371     -\arrayrulewidth)*#2-\tw@\tabcolsep-\arrayrulewidth\relax}%
372
373%%%%%%%%%%%%%%%%%%
374% --- MULTIROW ---
375% standard \multirow
376% 1. does not allow verbatim contents,
377% 2. does not allow blank lines in its argument,
378% 3. its * specifier means to typeset "horizontally" which is very
379%    bad for paragraph content. 2016 version has = specifier but it
380%    must be used with p type columns only, else results are bad,
381% 4. it requires manual intervention if the contents is too long to fit
382%    in the asked-for number of rows.
383% 5. colour panels (either from \rowcolor or \columncolor) will hide
384%    the bottom part of multirow text, hence manual tuning is needed
385%    to put the multirow insertion at the _bottom_.
386%
387% The Sphinx solution consists in always having contents wrapped
388% in a varwidth environment so that it makes sense to estimate how many
389% lines it will occupy, and then ensure by insertion of suitable struts
390% that the table rows have the needed height. The needed mark-up is done
391% by LaTeX writer, which has its own id for the merged cells.
392%
393% The colour issue is solved by clearing colour panels in all cells,
394% whether or not the multirow is single-column or multi-column.
395%
396% In passing we obtain baseline alignements across rows (only if
397% \arraystretch is 1, as LaTeX's does not obey \arraystretch in "p"
398% multi-line contents, only first and last line...)
399%
400% TODO: examine the situation with \arraystretch > 1. The \extrarowheight
401% is hopeless for multirow anyhow, it makes baseline alignment strictly
402% impossible.
403\newcommand\sphinxmultirow[2]{\begingroup
404  % #1 = nb of spanned rows, #2 = Sphinx id of "cell", #3 = contents
405  % but let's fetch #3 in a way allowing verbatim contents !
406  \def\sphinx@nbofrows{#1}\def\sphinx@cellid{#2}%
407  \afterassignment\sphinx@multirow\let\next=
408}%
409\def\sphinx@multirow {%
410  \setbox\z@\hbox\bgroup\aftergroup\sphinx@@multirow\strut
411}%
412\def\sphinx@@multirow {%
413  % The contents, which is a varwidth environment, has been captured in
414  % \box0 (a \hbox).
415  % We have with \sphinx@cellid an assigned unique id. The goal is to give
416  % about the same height to all the involved rows.
417  % For this Sphinx will insert a \sphinxtablestrut{cell_id} mark-up
418  % in LaTeX file and the expansion of the latter will do the suitable thing.
419  \dimen@\dp\z@
420  \dimen\tw@\ht\@arstrutbox
421  \advance\dimen@\dimen\tw@
422  \advance\dimen\tw@\dp\@arstrutbox
423  \count@=\dimen@       % type conversion dim -> int
424  \count\tw@=\dimen\tw@
425  \divide\count@\count\tw@ % TeX division truncates
426  \advance\dimen@-\count@\dimen\tw@
427  % 1300sp is about 0.02pt. For comparison a rule default width is 0.4pt.
428  % (note that if \count@ holds 0, surely \dimen@>1300sp)
429  \ifdim\dimen@>1300sp \advance\count@\@ne \fi
430  % now \count@ holds the count L of needed "lines"
431  % and \sphinx@nbofrows holds the number N of rows
432  % we have L >= 1 and N >= 1
433  % if L is a multiple of N, ... clear what to do !
434  % else write L = qN + r, 1 <= r < N and we will
435  % arrange for each row to have enough space for:
436  %     q+1 "lines" in each of the first r rows
437  %       q "lines" in each of the (N-r) bottom rows
438  % for a total of (q+1) * r + q * (N-r) = q * N + r = L
439  % It is possible that q == 0.
440  \count\tw@\count@
441  % the TeX division truncates
442  \divide\count\tw@\sphinx@nbofrows\relax
443  \count4\count\tw@ % q
444  \multiply\count\tw@\sphinx@nbofrows\relax
445  \advance\count@-\count\tw@ % r
446  \expandafter\xdef\csname sphinx@tablestrut_\sphinx@cellid\endcsname
447     {\noexpand\sphinx@tablestrut{\the\count4}{\the\count@}{\sphinx@cellid}}%
448  \dp\z@\z@
449  % this will use the real height if it is >\ht\@arstrutbox
450  \sphinxtablestrut{\sphinx@cellid}\box\z@
451  \endgroup % group was opened in \sphinxmultirow
452}%
453\newcommand*\sphinxtablestrut[1]{%
454  % #1 is a "cell_id", i.e. the id of a merged group of table cells
455  \csname sphinx@tablestrut_#1\endcsname
456}%
457% LaTeX typesets the table row by row, hence each execution can do
458% an update for the next row.
459\newcommand*\sphinx@tablestrut[3]{\begingroup
460  % #1 = q, #2 = (initially) r, #3 = cell_id, q+1 lines in first r rows
461  % if #2 = 0, create space for max(q,1) table lines
462  % if #2 > 0, create space for q+1 lines and decrement #2
463  \leavevmode
464  \count@#1\relax
465  \ifnum#2=\z@
466    \ifnum\count@=\z@\count@\@ne\fi
467  \else
468    % next row will be with a #2 decremented by one
469    \expandafter\xdef\csname sphinx@tablestrut_#3\endcsname
470      {\noexpand\sphinx@tablestrut{#1}{\the\numexpr#2-\@ne}{#3}}%
471   \advance\count@\@ne
472  \fi
473  \vrule\@height\ht\@arstrutbox
474        \@depth\dimexpr\count@\ht\@arstrutbox+\count@\dp\@arstrutbox-\ht\@arstrutbox\relax
475        \@width\z@
476  \endgroup
477  % we need this to avoid colour panels hiding bottom parts of multirow text
478  \sphinx@hack@CT
479}%
480
481\endinput
482