# Subfigures are right aligned

If I use subfigures to align two images side-by-side, these are right aligned. I tried several things but doesn't change anything. My current markup looks like this:

\usepackage{subfigure}

...

\begin{figure}[htbp]
\centering
\null\hfill
\subfigure[Lego Mindstorms Color Sensor 1]{\rule{4cm}{4cm}}
\hfill
\subfigure[Lego Mindstorms Color Sensor 2]{\rule{4cm}{4cm}}
\hfill\null
\rule{35em}{0.5pt}
\caption{Color / RGB Sensors}
\label{img:colorSensor}
\end{figure}


• Why did you add \null\fill to \centering? – Bernard Jan 24 '16 at 15:23
• ,@dannyyy - Yes, remove that \null\hfill before \centering as Bernard's hint. – AboAmmar Jan 24 '16 at 15:37
• You also need to replace the \hfill between the subfigures with \hfil. – John Kormylo Jan 24 '16 at 15:50

If your aim is to equalize the spaces, then \null\hfill is not the right way. Note that \null does not start horizontal mode (that is, a paragraph), so all it does is to create some vertical space.

Note also that subfigure has been obsolete and deprecated for 15 years.

\documentclass[10pt]{article}
\usepackage{showframe} % just for the example

\usepackage{subfig}

\begin{document}

\begin{figure}[htbp]
\centering

\hspace*{\fill}%
\subfloat[Lego Mindstorms Color Sensor 1]{\rule{4cm}{4cm}}
\hfill
\subfloat[Lego Mindstorms Color Sensor 2]{\rule{4cm}{4cm}}%
\hspace*{\fill}

\caption{Color / RGB Sensors}
\label{img:colorSensor}

\end{figure}

\end{document}


I suppose you want something like this:

\documentclass[10pt]{article}

\usepackage{subfigure}

\begin{document}

\begin{figure}[htbp]
\centering
\subfigure[Lego Mindstorms Color Sensor 1]{\rule{4cm}{4cm}}
\hspace{2em}
\subfigure[Lego Mindstorms Color Sensor 2]{\rule{4cm}{4cm}}
\rule{35em}{0.5pt}
\caption{Color / RGB Sensors}
\label{img:colorSensor}
\end{figure}

\end{document}


Output: