4

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.

5
  • 2
    The correct form is \begin{figure}\centering\includegraphics...\end{figure}. You can use \fbox{\includegraphics...} in order to see the real dimensions of your image. Maybe you are having some white space on one side.
    – LaRiFaRi
    Commented Jan 27, 2016 at 11:19
  • As LaRiFaRi suggest, I would think there is some whitespace in the image itself. Open Figure5_RPC_Problem_1 in an image viewer and check, crop if needed. Sidenote: As figure is a floating environment (i.e. it can move), it doesn't make sense to have it inside a center environment. Most likely it will simply float away and leave you with unwanted vertical space in the text. Commented Jan 27, 2016 at 11:24
  • @LaRiFaRi I have rewritten the code but the image is still on the right I am cropping it now.
    – Sebi
    Commented Jan 27, 2016 at 11:44
  • 2
    Try if the same happen iy you instead your real images use example-image from includegraphix package: \includegraphics[scale=0.4]{Figure5_RPC_Problem_1}\caption{Wider than figure text. Wider than figure text.Wider than figure text.} If it is centered (there is no reason to not be) than read above comments again!
    – Zarko
    Commented Jan 27, 2016 at 11:47
  • Cropping the image to the left did the trick.
    – Sebi
    Commented Jan 27, 2016 at 13:14

1 Answer 1

3

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}

You must log in to answer this question.

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