1

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!

1 Answer 1

3

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}
6
  • The first \noindent was not intentional, hehe, but thank you! :D
    – jfernandz
    Jul 28, 2016 at 13:38
  • And ... Is there anyway to concrete this for only one picture? I mean not to whole document?
    – jfernandz
    Jul 28, 2016 at 13:41
  • 1
    @JFernan yes you can just move the captionsetup to be local, or use the other feature of the caption package to apply options to a single caption. Jul 28, 2016 at 14:08
  • 1
    @JFernan the second was as bad:-) remember figure is a float so the \noindent and \\ are essentially being applied to "nothing" even if in the end the h option is used and the figure is placed more or less at that location. Jul 28, 2016 at 14:10
  • 1
    @JFernan the h in \begin{figure}[htp] Jul 28, 2016 at 16:17

You must log in to answer this question.

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