# Centering doesn't work for figure with tabularx

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

• Where did you read to use a tabular for that? And what is tabular ... ? Where did you read that/ – Johannes_B Sep 3 '15 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 '15 at 17:11
• Welcome to TeX.SX! I'm afraid you're overcomplicating things. :) – egreg Sep 3 '15 at 17:28

Another option using subfig.

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

• 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 '15 at 17:51
• I used your answer but with \quad from the other answer instead of \hfill, it looks better. Thanks. – David Prieto Sep 3 '15 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 '15 at 19:17

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}%
\subcaptionbox{Confirmación de eliminar (Android)}{%
\includegraphics[width=3cm]{example-image-9x16}%
`