ePub and Mobi Books Have Left Aligned Images


When compiling to ePub or Mobi with the Downsize and resample inline images to visible size option enabled in the Layout compile option pane, all images become left-aligned instead of centre-aligned.


(1) Disable resampling

If you can afford to, disabling the option will cause the bug to go away. It is only a problem while this option is enabled. The downside of this is that your image files will no longer be reduced in size to save space, and depending on how large your images were to start with, it could cause the total size of the Mobi file to become unacceptably large. One could resize the graphics down to a more e-book friendly source size using a graphic editing tool such as Photoshop, but that may impact the print-worthiness of the images if you are also compiling to other formats such as PDF.

For the more adventurous, read on.

(2) Fix the e-book after compiling

This will likely require a level of comfort with editing e-book files at a technical level, but these instructions will attempt to spell out each step as clearly as possible so that even someone unfamiliar with e-book formatting could fix their book.

For this fix you will need the following software:

  • Sigil: a WYSIWYG ePub editor.
  • Kindle Previewer: Amazon's official Kindle previewing and conversion software. You do not need this unless you are also publishing a Mobi file.
  1. Whether you are working with ePub, Mobi (or both): simply compile using ePub. We will convert the fixed ePub file to Mobi later on. There is no sense in fixing two books when you can fix it once.
  2. Open the compiled .epub file in Sigil.
  3. You will need to locate one of your images. Sigil's "Table of Contents" tool on the right-hand side is the easiest way to jump to a section you know contains an image.
  4. Scroll down to an image and place your cursor beside it.
  5. Press F2 to toggle the mode to code view.
  6. You should see in the highlighted line (or nearby) some text containing the code <img. That is the code that prints your image, but we don't need to do anything with it. What we are interested in is the "class" of the paragraph code this image falls within. An example of what this line may start like:

    <p class="p3"><span class="s1"><img alt="Image" ...

    The "p#" code within the "class" is what we are looking for. Jot down that number. In this example, it is "p3".

  7. In the Sigil left-hand sidebar, expand the "Styles" folder and double-click on each of the "stylesheet" files you see here to open them all up. We're going to be looking in each one of these for a line starting with "p#" and editing it. You should only have to edit one line in each file, but you may need to edit multiple files.

  8. Using the example above, the code is "p3", so I am looking for a line that starts with:

    p.p3 {margin: 0.0em 0.0em 0.0em 0.0em; text-indent: 0.0em; text-align: left}

    The part we need to fix is at the very end of that. Change the "text-align" value to from "left" to "center" so that each instance of this line in each stylesheet file looks like:

    p.p3 {margin: 0.0em 0.0em 0.0em 0.0em; text-indent: 0.0em; text-align: center}

  9. Click back on the section you opened initially in Sigil. You'll probably be in code view, so hit F2 again to return to WYSIWYG mode if necessary. The images should all now be centre-aligned. Check through the rest of the book and make sure they are all fixed. If you find any that are still left-aligned, then follow the same sequence of steps to locate the "p#" code, and then fix the stylesheet lines again for that one as well.

  10. Finally, hit Cmd-S to save your e-book and close Sigil.

At this point the ePub file is already fixed. You will need to do one more thing if you need a Mobi file as well:

  1. Open the .epub file that you've edited, using Kindle Previewer. This will automatically run KindleGen, converting the format to Mobi in the same fashion that a Mobi file is created directly out of Scrivener. It will be placed in a folder beside the ePub file.

Bug Status

This bug will be fixed in the next minor update.