[Tex/LaTex] Figure captions in minipage environment

captionsfloatshorizontal alignmentminipage

I would like to know how to force text centering; I've got this code:

\documentclass[8pt,a4paper,dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,color,caption}
\usepackage{epstopdf}
\usepackage[left=2cm,right=2cm,top=1.5cm,bottom=1.5cm]{geometry}

\begin{document}
\noindent

\noindent
\begin{figure}[htp]
    \begin{minipage}{0.5\textwidth}
        \centering
        \includegraphics[scale=0.225]{Pics/Absorcion.eps} \caption{In this case the caption is \\ too long and not being centered \\ like in second figure}
        \label{fig:Absor}
    \end{minipage}
\color{black}\vrule
    \begin{minipage}{0.5\textwidth}
        \centering
        \includegraphics[scale=0.2]{Pics/Emision.eps}\caption{Caption for \\ second figure}
        \label{fig:Emis}
    \end{minipage}
\end{figure}\\
\noindent

\end{document}

Which produces this result:

enter image description here

I would like to know why is not being centered and how could I force that! Thank you so much!

Best Answer

You can specify the alignment using the caption package that you are already using.

Also I fixed your minipages so they fit on a line.

enter image description here

\documentclass[8pt,a4paper,dvipsnames]{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx,color,caption}
\usepackage{epstopdf}
\usepackage[left=2cm,right=2cm,top=1.5cm,bottom=1.5cm]{geometry}
\captionsetup{justification=centering}
\begin{document}
%NO!\noindent

%NO!\noindent
\begin{figure}[htp]
    \begin{minipage}{0.45\textwidth}
        \centering
        \includegraphics[scale=0.225]{example-image} \caption{In this case the caption is \\ too long and not being centered \\ like in second figure}
        \label{fig:Absor}
    \end{minipage}%%%
{\hfill\color{black}\vrule\hfill}%
    \begin{minipage}{0.45\textwidth}
        \centering
        \includegraphics[scale=0.2]{example-image}\caption{Caption for \\ second figure}
        \label{fig:Emis}
    \end{minipage}%%
\end{figure}%NO!!!!\\
%NO!\noindent

\end{document}
Related Question