我无法让图片下方的标题与图片宽度相同(小于同一页中段落的宽度)。如何才能强制使标题宽度与图片宽度相同?
答案1
这caption
包裹提供一个width
可以为每个图形单独设置的参数。这样,您可以调整宽度以适合您的图形的宽度:
\documentclass{article}
\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{lipsum}% Just for this example
\usepackage{graphicx,caption}
\begin{document}
\begin{figure}[t]
\centering
\captionsetup{width=.8\linewidth}
\includegraphics[width=.8\linewidth, height=3\baselineskip]{example-image-a}
\caption[First figure]{\lipsum*[2]}
\end{figure}
\lipsum[1]
\begin{figure}[t]
\centering
\captionsetup{width=.9\linewidth}
\includegraphics[width=.9\linewidth, height=3\baselineskip]{example-image-b}
\caption[Second figure]{\lipsum*[2]}
\end{figure}
\end{document}
如果所有图形具有相同的宽度,则可以\captionsetup{width=<len>}
全局设置该选项。
答案2
答案3
最简单的解决方案可能是将模型放在包装measuredfigure
中的环境中threeparttable
。但请注意,此环境很脆弱,可能需要保护:
\documentclass[12pt, a4paper, twoside]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{fourier}
\usepackage{heuristica}
\usepackage[textwidth =15cm]{geometry}
\usepackage{graphicx}
\usepackage{caption, threeparttable}
\captionsetup{labelfont = sc, textfont = it}
\begin{document}
\begin{figure}
\centering\captionsetup{format = hang}
\begin{measuredfigure}
\includegraphics{Piero_di_Cosimo_3}
\caption{Portrait of Simonetta Vespucci\label{sen}}
\end{measuredfigure}
\end{figure}
\end{document}
另一种更强大的可能性是使用环境floatrow
并将其可选的宽度参数设置为\FBwidth
(=浮动框宽度):
\documentclass [11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{ebgaramond}
\usepackage{graphicx, caption} %
\usepackage{floatrow}
\usepackage{lipsum}
\captionsetup{font = small, labelsep = period}
\begin{document}
\lipsum[11]
\begin{figure}[!htb] % <-- see difference between your code and this MWE
\centering
\begin{floatrow}[1]
\ffigbox[\FBwidth]{\caption{Max Ernst: \emph{Two Children are treatened by a Nightingale} (1924)} \label{max_ernst}}%
{\includegraphics[scale = 0.75]{ernst-nightingale}}
\end{floatrow}
\end{figure}
\lipsum[14]
\end{document}