问题:
我正在尝试将三个图形彼此对齐,并将文本置于每个图形的中心。这很顺利,直到第三个框的框在文本宽度之后没有调整。
最小工作示例(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}