mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Fix #2593 (continued): allow figure captions in LaTeX tabulary tables
This commit is contained in:
@@ -837,9 +837,13 @@
|
||||
\newcommand{\literalblockwithoutcaptionneedspace}{1.5\baselineskip}
|
||||
|
||||
% figure in table
|
||||
\newenvironment{figure-in-table}[1][\linewidth]{
|
||||
\newenvironment{figure-in-table}[1][\linewidth]{%
|
||||
\def\@captype{figure}%
|
||||
\minipage{#1}%
|
||||
}{\endminipage}
|
||||
% store \caption to use it in longtable
|
||||
\let\figcaption\caption
|
||||
\begin{minipage}{#1}%
|
||||
}{\end{minipage}}
|
||||
% store original \caption macro for figures in longtable and tabulary
|
||||
\let\sphinxcaption\caption
|
||||
\newcommand*\figcaption
|
||||
{\ifx\equation$%$% this is trick to identify tabulary first pass
|
||||
\firstchoice@false\else\firstchoice@true\fi
|
||||
\sphinxcaption }
|
||||
|
||||
@@ -1437,9 +1437,11 @@ class LaTeXTranslator(nodes.NodeVisitor):
|
||||
# TODO: support align option
|
||||
if 'width' in node:
|
||||
length = width_to_latex_length(node['width'])
|
||||
self.body.append('\\begin{figure-in-table}[%s]\n\\centering' % length)
|
||||
self.body.append('\\begin{figure-in-table}[%s]\n\\centering\n' % length)
|
||||
else:
|
||||
self.body.append('\\begin{figure-in-table}\n\\centering')
|
||||
self.body.append('\\begin{figure-in-table}\n\\centering\n')
|
||||
if any(isinstance(child, nodes.caption) for child in node):
|
||||
self.body.append('\\capstart')
|
||||
self.context.append(ids + '\\end{figure-in-table}\n')
|
||||
elif node.get('align', '') in ('left', 'right'):
|
||||
if 'width' in node:
|
||||
|
||||
@@ -111,7 +111,7 @@ def test_writer(app, status, warning):
|
||||
app.builder.build_all()
|
||||
result = (app.outdir / 'SphinxTests.tex').text(encoding='utf8')
|
||||
|
||||
assert ('\\begin{figure-in-table}\n\\centering\n'
|
||||
assert ('\\begin{figure-in-table}\n\\centering\n\\capstart\n'
|
||||
'\\includegraphics{{img}.png}\n'
|
||||
'\\figcaption{figure in table}\\label{markup:id7}\\end{figure-in-table}' in result)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user