
問題:
我正在嘗試將三個圖形相鄰對齊,文字以每個圖形為中心。一切進展順利,直到第三個框的框在文字寬度之後不再調整。
最小工作範例 (MWE):
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\begin{document}
\begin{figure}[!tbp]
\centering
\begin{minipage}[b]{0.2\textwidth}
\includegraphics[width=\textwidth]{icon-password.eps}
\caption*{Login system}
\end{minipage}
\hfill
\begin{minipage}[b]{0.2\textwidth}
\includegraphics[width=\textwidth]{icon-shopping.eps}
\caption*{Shopping cart}
\end{minipage}
\hfill
\begin{minipage}[b]{0.2\textwidth}
\includegraphics[width=\textwidth]{icon-clock.eps}
\caption*{Temporary information}
\end{minipage}
\end{figure}
\end{document}
輸出:
調整文字後的寬度,以便「臨時訊息」可以寫在一行而不是兩行。
答案1
這是一個解決方案
\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\newlength{\mtfiglength}
\newcommand{\mtfigure}[3][\textwidth]{% #1 optional with of figure #2 caption #3 image filename
\settowidth{\mtfiglength}{#2}%
\begin{minipage}[b]{\mtfiglength}
\centering
\includegraphics[width=#1]{#3}
\caption*{#2}
\end{minipage}}
\begin{document}
\begin{figure}[!tbp]
\centering
\mtfigure{Login system}{example-image-a}\hfill
\mtfigure{Shopping cart}{example-image-b}\hfill
\mtfigure{Temporary information}{example-image}
\end{figure}
\begin{figure}[!tbp]
\centering
\mtfigure{Login system}{example-image-a}\hfill
\mtfigure{Shopping cart}{example-image-b}\hfill
\mtfigure[3cm]{Temporary information}{example-image}
\end{figure}
\end{document}