使用 tex4ht 将 html 中的图像居中

使用 tex4ht 将 html 中的图像居中

我正在尝试使用并转换 latex 文档为 html tex4ht,以获取居中图像。我受到了帖子中的代码的启发这里我使用以下.tex文件

\documentclass[12pt,a4paper,twoside]{book} \usepackage[francais]{babel}
\usepackage[latin1]{inputenc}
\usepackage{lmodern}
\usepackage{graphicx}
\usepackage{color}
\usepackage{float}
\usepackage{tex4ht}
\newtheorem{exemple}{Exemple}[chapter]
\newcommand\inputpstex[1]{\input{#1.pstex_t}}
\newcommand{\myTexFigure}[2]{
      \vspace{3mm}
    \begin{figure}[!h]
    \centering
    \inputpstex {#1}
    \caption{#2}\label{f:#1}
    \end{figure}
      \vspace{3mm}
      }
\title{Test}
\author{S.~Oulhoussine}
\begin{document}
\maketitle
\chapter{Introduction}
\section{Calcul}
Ceci est un test
\begin{exemple}[Pendule simple]
figure d'un pendule
\begin{figure}[!h]
  \centering
  \includegraphics[width=2cm]{pendule.ps}\\
  \caption{Image d'un pendule}
\end{figure}
\begin{equation}\label{linvar:e}
5 \cos (t) \frac{{dy(t)}}{{dt}}+ 3  y(t) = 10 u(t)
\end{equation}
\end{exemple}
L'exemple est déjà fini.
\end{document} 

我使用命令行进行转换

make4ht -c my.cfg test.tex

使用以下配置文件my.cfg

\Preamble{xhtml}
\Css{div.caption{text-align:center;}}
\Css{div.figure img {text-align:center;display:block;margin-left:auto; margin-right: auto;}}
\begin{document}
\EndPreamble

以下是 pendule.ps 和钟摆.pstex_t文件。我得到这个 html 文件 在此处输入图片描述 如您所见,html 图形未居中。您能帮忙吗?

答案1

您的配置文件中的 CSS 代码是正确的,它只是与 TeX4ht 源中的一个 CSS 声明冲突:

 \Css{.figure img.graphics {margin-left:10\%;}}

这会将图像的左边距设置为页面宽度的 10%。我真的不知道它为什么在那里,它似乎是一个非常古老的声明,不再有用。所以我会从源中删除它。要立即修复它,您可以使用 CSS 声明覆盖它,该声明将具有比上述声明更高的特异性:

 \Css{figure.figure img.graphics {text-align:center;display:block;margin-left:auto; margin-right: auto;}}

这是不同图像的结果:

在此处输入图片描述

相关内容