4

I have a figure with 3 images in it, searching TeX I found out that the best way to accomplish that was with a tabularx inside a figure, like this:

\begin{figure}[t]
\centering
\def\tabularxcolumn#1{m{#1}}
\begin{tabularx}{\linewidth}{c}
%
  \begin{tabular}{ccc}
    \subfloat[Opciones de mensaje]{\includegraphics[width=3cm,type=png,ext=.png,read=.png,angle=0]{imagenes/pantalla11}} 
    & \subfloat[Confirmación de eliminar (Android)]{\includegraphics[width=3cm,type=png,ext=.png,read=.png,angle=0]{imagenes/pantalla12}}
    & \subfloat[Confirmación de eliminar (iOS)]{\includegraphics[width=3cm,type=png,ext=.png,read=.png,angle=0]{imagenes/iOSelim}}\\
  \end{tabular}
\end{tabularx}

\caption{Pantalla de Buzón con opciones de mensaje. Elaboración propia.}\label{fig:pantallaMulti2}
\end{figure}

It shows the multiple figures, but the whole figure is positioned to the left, not the center, like is ignoring the \centering instruction.

Any ideas? First time I use LaTex.

3
  • 1
    Where did you read to use a tabular for that? And what is tabular ... ? Where did you read that/
    – Johannes_B
    Sep 3, 2015 at 17:11
  • Your best bet seems to be to ckick out everything related to tabular material; or use \centering inside the tabularx.
    – Johannes_B
    Sep 3, 2015 at 17:11
  • Welcome to TeX.SX! I'm afraid you're overcomplicating things. :)
    – egreg
    Sep 3, 2015 at 17:28

2 Answers 2

4

Another option using subfig.

enter image description here

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{subfig,graphicx}
\begin{document}

\begin{figure}

\subfloat[Opciones de mensaje]{\includegraphics[width=3cm]{example-image-a}} 
\hfill
\subfloat[Confirmación de eliminar (Android)]{\includegraphics[width=3cm]{example-image-b}}
\hfill
\subfloat[Confirmación de eliminar (iOS)]{\includegraphics[width=3cm]{example-image-c}}

\caption{Pantalla de Buzón con opciones de mensaje. Elaboración propia.}\label{fig:pantallaMulti2}

\end{figure}

\end{document} 

As stated by @egreg, you're overcomplicating things. You can just put the figures one beside another and \hfill will distribute them horizontally.

3
  • You should add the instructions \usepackage[T1]{fontenc} and \usepackage[utf8]{inputenc} to the preamble, in order to properly process accented characters (such as ó). Loading the babel package with the option spanish would also be a good idea.
    – Mico
    Sep 3, 2015 at 17:51
  • I used your answer but with \quad from the other answer instead of \hfill, it looks better. Thanks. Sep 3, 2015 at 18:58
  • @AboAmmar, if you use \hfill to separate sub figures, than \centering is superfluous :-). With use of centering˛the use of \hfil` (one l!) has sense. With use of both (\centering and \hfil) the sub figures are equally horizontally spaced.
    – Zarko
    Sep 3, 2015 at 19:17
3

You're overcomplicating things: you don't need tabularx at all, because as you're using it it's just for getting a normal paragraph as wide as the normal text width.

Also the subcaptions should be aligned, which is much easier using subcaption instead of subfig (that's recommended only in some special cases) and its \subcaptionbox command.

There's no need to specify everytime type=png,ext=.png,read=.png,angle=0, because LaTeX will pick up a PNG file if it finds it by the specified name.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}

\usepackage{graphicx}
\usepackage{subcaption}

\usepackage{lipsum} % for mock text

\begin{document}

\lipsum[2]

\begin{figure}[htp]
\centering

\subcaptionbox{Opciones de mensaje}{%
  \includegraphics[width=3cm]{example-image}%
}\quad
\subcaptionbox{Confirmación de eliminar (Android)}{%
  \includegraphics[width=3cm]{example-image-9x16}%
}\quad
\subcaptionbox{Confirmación de eliminar (iOS)}{%
  \includegraphics[width=3cm]{example-grid-100x100bp}%
}

\caption{Pantalla de Buzón con opciones de mensaje. Elaboración propia.}
\label{fig:pantallaMulti2}

\end{figure}

\lipsum[3]

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .