minipage
我使用以下方法将 2 个图形并排放置这个帖子,图形看起来完全正常。但是,右侧图形的标题突出到页边距,这是为什么?我该如何修复?
我的代码是这样的:
\begin{figure}[htbp]
\centering
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=6.6cm]{figure1.png}
\caption{Caption for figure 1.}
\label{fig:fig1}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\centering
\includegraphics[width=6.6cm]{figure2.png}
\caption{Caption for figure 2, but longer.}
\label{fig:fig2}
\end{minipage}
\end{figure}
答案1
这是实现您想要的最简单的方法:
\documentclass{article}
\usepackage[demo]{graphicx} % [demo] is just for the example
\begin{document}
\begin{figure}
\centering
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.8\textwidth,height=4cm]{a}
\caption{A not so wide caption}
\end{minipage}\hfill
\begin{minipage}[t]{.45\textwidth}
\centering
\includegraphics[width=.8\textwidth,height=4cm]{a}
\caption{A caption that should be wider than the figure, but so wide that it should wrap}
\end{minipage}
\end{figure}
\end{document}
这里假设两张图片具有相同的高度,以便获得字幕的正确对齐。
答案2
我建议你选择这个subcaption
包,因为这是它的用途,然后做这样的事情:
\documentclass{article}
\usepackage{graphicx}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics[scale=1]{MuscularTissue3_1}
\caption{Skeletal}
\label{fig:SkeletalTissue}
\end{subfigure}
\begin{subfigure}[b]{.5\linewidth}
\centering
\includegraphics[scale=1]{MuscularTissue3_2}
\caption{Cardiac}
\label{fig:CardiacTissue}
\end{subfigure}
\caption{Two Types of Muscular Tissue}
\label{fig:MuscularTissue}
\end{figure}
If you want to reference the first figure (Figure~\ref{fig:SkeletalTissue}), if you want the second (Figure~\ref{fig:CardiacTissue}). If you want to reference both (Figure~\ref{fig:MuscularTissue}
\end{document}
我没有你的数据,所以我只放了一些我自己的数据。输出结果如下:
欲了解更多信息,请参阅subfigure
文档
答案3
我自己也遇到了这个问题并找到了我认为的解决方案:
\documentclass{article}
\usepackage[demo]{graphicx} % [demo] is just for the example
\usepackage{caption}
\begin{document}
\begin{figure}[h!]
\centering
\captionsetup{width=0.45\textwidth} % Choose 0.45 to leave some space between captions
\begin{minipage}{0.49\textwidth} % Choose 0.49 to prevent minipages stacking
\centering
\includegraphics[width=0.95\textwidth]{a} % Choose smaller than 1 to have space between figures
\captionof{figure}{Caption text for figure 1 and it is quite long.}\label{fig:figure1}
\end{minipage}
\begin{minipage}{0.49\textwidth} % Choose 0.49 to prevent minipages stacking
\centering
\includegraphics[width=0.95\textwidth]{a} % Choose smaller than 1 to have space between figures
\captionof{figure}{Caption text for figure 2 and it is quite long.}\label{fig:figure2}
\end{minipage}
\end{figure}
\end{document}
摘要:将 \caption{caption text} 更改为 \captionof{figure}{caption text} 并使用 'caption' 包设置宽度。
问候,
恩斯特·简