mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Separate `\sphinxcapstartof
` macro, to facilitate caption below table
This commit is contained in:
parent
2034be9b9e
commit
069b937513
@ -11,6 +11,7 @@
|
|||||||
\centering
|
\centering
|
||||||
<%- endif %>
|
<%- endif %>
|
||||||
<% if table.caption -%>
|
<% if table.caption -%>
|
||||||
|
\sphinxcapstartof{table}
|
||||||
\sphinxcaptionof{table}{<%= ''.join(table.caption) %>}<%= labels %>
|
\sphinxcaptionof{table}{<%= ''.join(table.caption) %>}<%= labels %>
|
||||||
\sphinxaftercaption
|
\sphinxaftercaption
|
||||||
<% endif -%>
|
<% endif -%>
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
\centering
|
\centering
|
||||||
<%- endif %>
|
<%- endif %>
|
||||||
<% if table.caption -%>
|
<% if table.caption -%>
|
||||||
|
\sphinxcapstartof{table}
|
||||||
\sphinxcaptionof{table}{<%= ''.join(table.caption) %>}<%= labels %>
|
\sphinxcaptionof{table}{<%= ''.join(table.caption) %>}<%= labels %>
|
||||||
\sphinxaftercaption
|
\sphinxaftercaption
|
||||||
<% endif -%>
|
<% endif -%>
|
||||||
|
@ -105,29 +105,30 @@
|
|||||||
\let\sphinxattableend\sphinxatlongtableend
|
\let\sphinxattableend\sphinxatlongtableend
|
||||||
% longtable's wraps captions to a maximal width of \LTcapwidth
|
% longtable's wraps captions to a maximal width of \LTcapwidth
|
||||||
% so we do the same for all tables
|
% so we do the same for all tables
|
||||||
|
\newcommand*\sphinxcapstartof[1]{%
|
||||||
|
\vskip\parskip
|
||||||
|
\vbox{}% force baselineskip for good positioning by capstart of hyperanchor
|
||||||
|
\def\@captype{#1}%
|
||||||
|
\capstart
|
||||||
|
% move back vertically to compensate space inserted by next paragraph
|
||||||
|
\vskip-\baselineskip\vskip-\parskip
|
||||||
|
}%
|
||||||
\newcommand\sphinxcaptionof[3][\LTcapwidth]{%
|
\newcommand\sphinxcaptionof[3][\LTcapwidth]{%
|
||||||
\noindent\hb@xt@\linewidth{\hss
|
\noindent\hb@xt@\linewidth{\hss
|
||||||
\vtop{\@tempdima\dimexpr#1\relax
|
\vtop{\@tempdima\dimexpr#1\relax
|
||||||
% don't exceed linewidth for the caption width
|
% don't exceed linewidth for the caption width
|
||||||
\ifdim\@tempdima>\linewidth\hsize\linewidth\else\hsize\@tempdima\fi
|
\ifdim\@tempdima>\linewidth\hsize\linewidth\else\hsize\@tempdima\fi
|
||||||
\def\@captype{#2}%
|
|
||||||
\capstart % must be after setting \@captype
|
|
||||||
% longtable ignores \abovecaptionskip/\belowcaptionskip, so do the same here
|
% longtable ignores \abovecaptionskip/\belowcaptionskip, so do the same here
|
||||||
\abovecaptionskip\z@skip
|
\abovecaptionskip\z@skip
|
||||||
\belowcaptionskip\z@skip
|
\belowcaptionskip\z@skip
|
||||||
% hyperref anchor (and a \write) cause the \vtop to have zero height. Hence if
|
|
||||||
% the caption is first thing in a list item, the item label (which gets
|
|
||||||
% inserted indirectly by the \noindent) will have its baseline same as top of
|
|
||||||
% box which is \ht\strutbox above the caption text baseline. This avoids a
|
|
||||||
% wide caption overwriting the item label.
|
|
||||||
\caption[{#3}]%
|
\caption[{#3}]%
|
||||||
{\strut\ignorespaces#3\ifhmode\unskip\@finalstrut\strutbox\fi}%
|
{\strut\ignorespaces#3\ifhmode\unskip\@finalstrut\strutbox\fi}%
|
||||||
}\hss}%
|
}\hss}%
|
||||||
\par\prevdepth\dp\strutbox
|
\par\prevdepth\dp\strutbox
|
||||||
}%
|
}%
|
||||||
\newcommand\sphinxaftercaption
|
\newcommand\sphinxaftercaption
|
||||||
{% the default definition serves with a caption above a table, to make sure its
|
{% this default definition serves with a caption *above* a table, to make sure
|
||||||
% last baseline is \sphinxbelowcaptionspace above table top rule
|
% its last baseline is \sphinxbelowcaptionspace above table top
|
||||||
\nobreak
|
\nobreak
|
||||||
\vskip\dimexpr\sphinxbelowcaptionspace\relax
|
\vskip\dimexpr\sphinxbelowcaptionspace\relax
|
||||||
\vskip-\baselineskip\vskip-\parskip
|
\vskip-\baselineskip\vskip-\parskip
|
||||||
|
@ -895,6 +895,7 @@ def test_latex_table_tabulars(app, status, warning):
|
|||||||
# table having caption
|
# table having caption
|
||||||
table = tables['table having caption']
|
table = tables['table having caption']
|
||||||
assert ('\\begin{savenotes}\\sphinxattablestart\n\\centering\n'
|
assert ('\\begin{savenotes}\\sphinxattablestart\n\\centering\n'
|
||||||
|
'\\sphinxcapstartof{table}\n'
|
||||||
'\\sphinxcaptionof{table}{caption for table}'
|
'\\sphinxcaptionof{table}{caption for table}'
|
||||||
'\\label{\\detokenize{tabular:id1}}\n'
|
'\\label{\\detokenize{tabular:id1}}\n'
|
||||||
'\\sphinxaftercaption' in table)
|
'\\sphinxaftercaption' in table)
|
||||||
|
Loading…
Reference in New Issue
Block a user