[Tex/LaTex] Centering images in lyx

graphicshorizontal alignmentlyx

I am having some trouble in centering images in lyx and have read a number
of questions on the topic. However, when attempting to apply the solutions from the answers the images are still not centered. The code in lyx is:

\begin{figure}
\includegraphics[scale=0.4]{Figure5_RPC_Problem_1}\caption{Wider than figure text. Wider than figure text.}
\end{figure}

I tried using the centering commands:

  1. \centering\includegraphics{...} when the figure is smaller than the text width
  2. \centerline{\includegraphics{...}} when the figure is wider than the text width
\begin{figure}
\centering\includegraphics[scale=0.4]{Figure5_RPC_Problem_1}\caption{Wider than figure text. Wider than figure text. Wider than figure text.Wider than figure text.Wider than figure text.}
\end{figure}

and

\begin{figure}
\centerline{\includegraphics[scale=0.4]{Figure5_RPC_Problem_1}\caption{Wider than figure text. Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.}}
\end{figure}

but the output is still the same. Next I tried using the center environment but the image is still not centered

\begin{center}
\begin{figure}
    \centerline{\includegraphics[scale=0.4]{Figure5_RPC_Problem_1}\caption{Wider than figure text. Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.}}
    \end{figure}
\end{center}

The document now looks like:

centering images is lyx

A link to the image can be found here.

Edit:

I have modified the code to:

\begin{figure}
\centering\includegraphics[scale=0.4]{Figure5_RPC_Problem_1}\caption{Wider than figure text. Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.}
\end{figure}

but the image is still placed slightly to the right.

Best Answer

After cropping the image, I've used the following latex code:

\begin{figure}
\centering\includegraphics[scale=0.4]{Figure5_RPC_Problem_1}\caption{Wider than figure text. Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.Wider than figure text.}
\end{figure}

In lyx, the graphicx package must be included in the preamble:

Go to Document Settings Preamble and add

\usepackage{graphicx}