小页面中的图片标题

小页面中的图片标题

我正在尝试将两张图片放在同一行。我在网上找到了一些似乎效果很好的解决方案,我决定使用这个:

\begin{figure}[!ht]
\begin{minipage}[c]{8cm}
    \centering
    \includegraphics[width =\textwidth]{money_spend_on_cloud.png}
    \caption{money spend on cloud}
\end{minipage}
\hfill
\begin{minipage}[c]{8cm}
    \centering      
    \includegraphics[width=\textwidth]{WB-graph.jpg}
    \caption{Cloud storage}
\end{minipage}
\end{figure}

两幅图在同一页上。但是,我只有一个标题,它占据了整个页面(不仅限于其小页面),我不明白为什么。似乎第一张图片的标题不知何故位于第二张图片的标题“下方”,因此不可见,但由于标题位于单独的小页面上,因此不应该如此。

另外,此代码用于许多示例,并且标题位置很好 :/

有人能帮我解决这个问题吗?问题如下: 字幕问题

编辑:由于它在在线示例中运行良好,我猜它来自我的文档类。我是对的。我的文档类中有以下几行:

\newlength{\float@capnamewd}   % neu
\newlength{\float@cparwidth}   % neu
\newsavebox{\float@capnamebox} % neu
\renewcommand\floatc@ruled[2]{%
\savebox{\float@capnamebox}{\@fs@cfont #1\hspace*{1.5ex}}
\settowidth{\float@capnamewd}{\usebox{\float@capnamebox}}%
\setlength{\float@cparwidth}{\hsize}%
\addtolength{\float@cparwidth}{-1.0\float@capnamewd}%
\usebox{\float@capnamebox}\parbox[t]{\float@cparwidth}{#2\par}}
\renewcommand\fs@ruled{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
\def\@fs@pre{}%
\def\@fs@post{\kern2.5pt\hrule height.1pt depth0pt\relax}%
\def\@fs@mid{\kern2pt\hrule height.1pt depth0pt \kern2.5pt}%
\def\@fs@cfont{\captionfont\bfseries}
\let\@fs@iftopcapt\iffalse}
\floatstyle{ruled}
\restylefloat{figure}
\restylefloat{table}

我不知道这是什么意思,但显然是关于图片和标题的。当我把它作为注释时,我的图片代码就可以正常工作了。这就是我得到的(也是我想要的):

在此处输入图片描述

标题格式不一样,但我一点也不关心。但是,我想了解文档类中的这些行的作用。有人能解释一下这些行吗?也许我不必把所有内容都放在注释中……

编辑:因此,尝试查看我的 wissdoc 中到底有什么问题,我最终只添加了以下行

\restylefloat{figure}

在注释中。所以如果我认为之前的所有行都在定义一种新的浮动样式,那么这行将它应用于图形。但这种新的浮动样式对我来说很糟糕。但是,当我把除了这一行之外的所有行都放在注释中时,我仍然遇到问题。标题的格式与我的第二张图片相同,但只有第二个标题的位置与我的第一张图片相同。我不明白。

答案1

首先,我使用 floatrow 来模拟您的文档类。

\documentclass{article}
\usepackage{floatrow}
\floatsetup{style=ruled,capposition=bottom}
\usepackage{graphicx}

\begin{document}
\begin{figure}[!ht]
\begin{minipage}[c]{0.45\textwidth}
    \centering
    \includegraphics[width =\textwidth]{example-image-a}
    \caption{money spend on cloud}
\end{minipage}
\hfill
\begin{minipage}[c]{0.45\textwidth}
    \centering      
    \includegraphics[width=\textwidth]{example-image-b}
    \caption{Cloud storage}
\end{minipage}
\end{figure}

\end{document}

问题

然后我使用 paracol 来实现所需的效果,同时保持设计者意图。与 multicol 不同,paracol 支持浮动。如果这会导致分页,您可能需要使用 \afterpage(afterpage 包)。

\documentclass{article}
\usepackage{floatrow}
\floatsetup{style=ruled,capposition=bottom}
\usepackage{graphicx}
\usepackage{paracol}% support floats
\globalcounter{figure}

\begin{document}
\begin{paracol}{2}
\begin{figure}
    \centering
    \includegraphics[width =\columnwidth]{example-image-a}
    \caption{money spend on cloud}
\end{figure}
\switchcolumn
\begin{figure}
    \centering      
    \includegraphics[width=\columnwidth]{example-image-b}
    \caption{Cloud storage}
\end{figure}
\end{paracol}

\end{document}

解决方案

答案2

我相信该\caption命令无法识别minipage环境,但对该figure环境仅起作用一次。因此您的示例中只有一个标题。

相反,请尝试使用包\captionof中的命令caption。在您的示例中,可以使用以下命令轻松修复此问题:

....rest of preamble....
\usepackage{caption}
\begin{document}
\begin{figure}[!ht]
\begin{minipage}[c]{8cm}
    \centering
    \includegraphics[width =\textwidth]{money_spend_on_cloud.png}
    \captionof{figure}{money spend on cloud}
\end{minipage}
\hfill
\begin{minipage}[c]{8cm}
    \centering      
    \includegraphics[width=\textwidth]{WB-graph.jpg}
    \captionof{figure}{Cloud storage}
\end{minipage}
\end{figure}
\end{document}

这应该会给你想要的每个图形的标题。

相关内容