1

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}
    \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}

Outputs:

enter image description here 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
2

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{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}

enter image description here

| improve this answer | |
  • Still the same problem with the clock, it becomes bigger. See following: dropbox.com/s/nakgd7r5mxi40s9/… – kexxcream Aug 3 '15 at 9:41
  • @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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.