【问题标题】:Caption Centered To Image Rather Than Page以图像而不是页面为中心的标题
【发布时间】:2021-12-31 20:59:33
【问题描述】:

这里没有任何代码,因为我只想将 \begin{figure}\end{figure} 的标题居中到包含的图像的中心而不是页面的中心,如果我将图像居中到左边,标题仍然出现在页面的中心(不使用 minipage,因为这是我现在知道的唯一方法)。

这是一个例子:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\begin{document}
\begin{figure}[h]
    \includegraphics[width=0.5\textwidth]{image.png}
    \caption{Caption}
\end{figure}
\end{document}

我从编译中得到什么:

我希望它以图像本身而不是页面为中心,不使用 minipage。

Here is the source image btw, just some image I found on google

【问题讨论】:

标签: latex text-alignment


【解决方案1】:

使用varwidth 包的一种可能方法:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{varwidth}
\begin{document}
\begin{figure}[h]
\begin{varwidth}{\linewidth}
    \includegraphics[width=0.5\textwidth]{example-image-duck}
    \caption{Caption}
\end{varwidth}    
\end{figure}
\end{document}

【讨论】:

  • 但它会将标题向左对齐,您可以直接使用\centering 并更改它吗?
  • @AmarnathK 哦,对不起,我误解了你的问题。让我试试别的吧
  • @AmarnathK 请查看我更新的帖子。 varwidth 环境会自动适应图像的宽度,因此标题位于其下方居中(如果标题比图像短,如果它更长,我会使用标题包左对齐)
  • 好的,非常感谢!
  • 你知道在哪里发布随机 pdf 的东西吗,因为我在空闲时间做了很多,并且想用它们做点什么
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-01
  • 2015-08-21
  • 1970-01-01
  • 2019-05-25
  • 1970-01-01
相关资源
最近更新 更多