[Tex/LaTex] Subfigures are right aligned

horizontal alignmentsubfloats

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}

enter image description here

Best Answer

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}

enter image description here