我正在使用 tex4ebook 生成 epub。我希望子图与子图下方的子标题并排放置。我遇到了几个问题,如果能提供任何解决这些问题的提示,我将不胜感激。
我如何获得并排的子图?
我使用了这些问题答案中的建议来配置并提供图形和子图的 CSS:htlatex 和子图
这是我得到的结果的一部分。另一部分是一对子图,除了标题外,其余都相同。
配置文件
\Preamble{xhtml}
\ConfigureEnv{figure}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="figure">}%
\bgroup \Configure{float}{\ShowPar}{}{}%
}
{\egroup
\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar
\par}
{}{}
\Css{div.caption{text-align:center;font-size:83\%;text-indent:0em;margin-left:2em;margin-right:2em;}}
\Css{div.figure{text-align:center;clear:both;overflow:auto;width:100\%;margin-bottom:1em;}}
\ConfigureEnv{subfigure}
{\ifvmode\IgnorePar\fi\EndP\HCode
{<div class="subfigure"\Hnewline>}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
{}{}
\Css{div.subfigure {text-align:center;display:inline-block; max-width:45\%;}}
\Css{.subfigure img{display:block; margin-left:auto;margin-right:auto;}}
\ConfigureEnv{subfigurecaption}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="subfigurecaption">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
{}{}
\Css{.subfigcaption {margin-top:1em;margin-left:1em;}}
\makeatletter
\DeclareGraphicsExtensions{.svg,.png}
\ExplSyntaxOn
\Configure{Gin-dim}
{style="width:\fp_eval:n{round(\Gin@req@width/\textwidth*100,2)}\%;max-height:\fp_eval:n{round(\Gin@req@height/\textwidth*100,2)}\%;"}
\ExplSyntaxOff
\makeatother
\begin{document}
\EndPreamble
麦格
\documentclass{book}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\include{included}
\begin{figure}[htbp]
\caption{A pair of frogs}
\centering
\begin{subfigure}[b]{0.45\textwidth}
\caption{Third Frog}
\label{fig:frogone}
\includegraphics[width=0.36\textwidth, keepaspectratio]{./images/simplefrog.png}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\caption{Fourth Frog}
\label{fig:frogtwo}
\includegraphics[width=0.36\textwidth, keepaspectratio]{./images/simplefrog.png}
\end{subfigure}
\end{figure}
包括.tex
\begin{figure}[htbp]
\caption{Included frogs}
\centering
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[height=0.36\textwidth, keepaspectratio]{./images/simplefrog.svg}
\caption{First Frog}
\end{subfigure}
\begin{subfigure}[b]{0.45\textwidth}
\centering
\includegraphics[height=0.36\textwidth, keepaspectratio]{./images/simplefrog.svg}
\caption{Second Frog}
\end{subfigure}
\end{figure}
当我注释掉\Css{.subfigure img{display:block; margin-left:auto;margin-right:auto;}}
这些图形时,它们的比例是正确的,但是当子图插入到顶层 .tex 文件时,其样式与使用 \include 插入时的样式不同(子标题位于子图旁边,而不是在其下方)。
这就引出了我的第二个问题:
我该怎么做才能确保当使用 \include 插入子图时,子图的样式不会改变?
当我在 .cfg 中注释掉我提到的行 (subfigure img 的 css) 时,.epub 的样子如下:
mwe.html
<?xml version='1.0' encoding='utf-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title></title>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
<meta name='generator' content='TeX4ht (https://tug.org/tex4ht/)' />
<meta name='originator' content='TeX4ht (https://tug.org/tex4ht/)' />
<!-- charset=utf-8,epub,uni-html4,html,xhtml -->
<meta name='src' content='mwe.tex' />
<link type='text/css' rel='stylesheet' href='mwe.css' />
</head><body>
<div class='figure'>
<a id='x1-2r1'></a>
<a id='x1-3'></a>
<br /> <div class='caption'><span class='id'>
Figure 1: </span><span class='content'>Included frogs
</span></div><!-- tex4ht:label?: x1-2r -->
<div class='subfigure'><!-- l. 7 --><p class='noindent'><img alt='PIC' src='./images/simplefrog.png' style='width:36%;max-height:36%;' /> <a id='x1-4r1'></a>
<span class='cmr-9'>(a) First Frog</span>
</p></div> <div class='subfigure'><img alt='PIC' src='./images/simplefrog.png' style='width:36%;max-height:36%;' /> <a id='x1-5r2'></a>
<span class='cmr-9'>(b) Second Frog</span>
</div>
</div>
<div class='figure'>
<a id='x1-6r2'></a>
<a id='x1-7'></a>
<br /> <div class='caption'><span class='id'>
Figure 2: </span><span class='content'>A pair of frogs
</span></div><!-- tex4ht:label?: x1-6r -->
<div class='subfigure'><a id='x1-8r1'></a>
<!-- l. 14 --><p class='noindent'><span class='cmr-9'>(a) Third Frog</span>
</p><!-- l. 16 --><p class='noindent'><img alt='PIC' src='./images/simplefrog.png' style='width:36%;max-height:36%;' />
</p></div> <div class='subfigure'><a id='x1-9r2'></a>
<span class='cmr-9'>(b) Fourth Frog</span>
<!-- l. 21 --><p class='noindent'><img alt='PIC' src='./images/simplefrog.png' style='width:36%;max-height:36%;' />
</p></div>
</div>
</body></html>
答案1
您的配置文件对我来说很管用。不过我会稍微修改一下。首先,我们可以为包添加一个配置subcaption
文件subcaption.4ht
:
\NewConfigure{subfigure}{2}
\ConfigureEnv{subfigure}{\a:subfigure}{\b:subfigure}{}{}
\ConfigureEnv{subtable}{\a:subfigure}{\b:subfigure}{}{}
\Hinput{subcaption}
它定义了新的配置钩子subfigure
。你可以修改该.cfg
文件来使用它:
\Preamble{xhtml}
\ConfigureEnv{figure}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="figure">}%
\bgroup \Configure{float}{\ShowPar}{}{}%
}
{\egroup
\ifvmode\IgnorePar\fi\EndP\HCode{</div>}\ShowPar
\par}
{}{}
\Configure{subfigure}
{\ifvmode\IgnorePar\fi\EndP%
\HCode{<div class="subfigure">}\par\ShowPar
}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
\Css{figure.float, div.figure {margin-left: auto; margin-right: auto; text-align:center;}}
\Css{figure.float img, figure.figure img {display: block; margin-left: auto; margin-right: auto;}}
\Css{figure.figure {text-align:center;}}
\Css{figcaption.caption, div.caption {text-indent:-2em; margin-left:3em; margin-right:1em; text-align:center;}}
\Css{figcaption.caption span.id{font-weight: bold; white-space: nowrap; }}
\Css{div.subfigure {text-align:center;display:inline-block; max-width:45\%;}}
\makeatletter
\ExplSyntaxOn
\Configure{Gin-dim}
{style="width:\fp_eval:n{round(\Gin@req@width/\textwidth*100,2)}\%;max-height:\fp_eval:n{round(\Gin@req@height/\textwidth*100,2)}\%;"}
\ExplSyntaxOff
\makeatother
\begin{document}
\EndPreamble
结果如下: