Fix #2593 (continued): allow figure captions in LaTeX tabulary tables

This commit is contained in:
jfbu
2016-06-05 14:21:21 +09:00
committed by Takeshi KOMIYA
parent bb6bb7ded6
commit 96e30b0d0e
3 changed files with 14 additions and 8 deletions
+9 -5
View File
@@ -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 }
+4 -2
View File
@@ -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:
+1 -1
View File
@@ -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)