# Aligning three figures next to each other based on text width

Problem:

I am trying to align three figures next to each other with text centered to each figure. This is going well until the box for the third box does not adjust after the text width.

Minimal Working Example (MWE):

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}

\begin{document}

\begin{figure}[!tbp]
\centering
\begin{minipage}[b]{0.2\textwidth}
\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}


Outputs:

Desired outcome:

To get the width to adjust after the text so that "Temporary information" can be written out in one line instead of two.

• first remark use 0.5\textwidth for last minipage – touhami Aug 3 '15 at 8:46
• Thanks, but that will only make the clock bigger. Is there a more dynamic solution where the width would adjust to the text? – kexxcream Aug 3 '15 at 8:48
• ok i see your problem – touhami Aug 3 '15 at 9:09

Here is a solution

\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{Shopping cart}{example-image-b}\hfill
\mtfigure{Temporary information}{example-image}
\end{figure}

\begin{figure}[!tbp]
\centering

• @kexxcream try like this \mtfigure[3cm]{Temporary information}{icon-clock.eps} where 3cm is the width you want for the image it can be 2cm ,4cm or any length – touhami Aug 3 '15 at 9:45