How to left-justify a PNG image file?

I dragged-and-dropped a PNG file into the Scrivener editor. It shows as left-justified in the editor, which is what I want. But when I compile and look at the resulting ePub in Apple Books or in Kindle Previewer, the PNG image is centered. Is there a setting somewhere in Scrivener that says, in essence, “keep PNG image left justified”?

Attached is an image showing this situation, as well as my test file.


Justify.scriv.zip (319 KB)

There isn’t a specific setting per se, but you can override any and all of Scrivener’s default formatting choices. With ebooks, if you cannot find a checkbox for it, the next place to look is CSS (and if you’re comfortable with CSS sometimes you can just forget about hunting down checkboxes and do what you want directly, as often checkboxes just drive the CSS).

To use your sample project as an example:

  1. Go into Compile and edit your “ePub 3” Format.

  2. Select the CSS pane. Now the first thing you need to do here is give yourself the ability to override Scrivener’s CSS. Change the dropdown in the middle to “Append Custom CSS Stylesheet”.

  3. On the left side is the stuff you can edit. You can’t change the stuff on the right, but given how CSS works and given how the left side will be appended beneath the right side, you can override anything in the right column. We’ll be doing both.

  4. Search for “figure” in the left column. You’ll see a some explanatory text followed by instructions for how to format figures. You want something like this:

    figure { page-break-inside: avoid; text-align: left; margin: 0em 0em 0em 0em; }
    figcaption { text-align: inherit; }
    

    This changes the text-align setting that Scrivener sets, and it also adds a margin setting override. Although Scrivener won’t do so, you may find some book readers actually force figures to be centre-aligned if they are not otherwise declared. The next line, regarding figcaption, ensures that its alignment follows along with the figure environment.

  5. Next you’ll want to fix how images themselves are padded within the figure environment, to simulate centre-alignment. Search for “img” in the right column. Again you cannot edit this, but you can override it by providing your own instructions for the same selector, on the left. So copy the “img” line and paste it below the bit you just edited above.

  6. Edit the margin text so that where you see the word ‘auto’, change it to ‘0rem’. (That’s a zero.) So to bring it all together, you should now have something that looks a bit like this at the bottom of the “Custom Stylesheet” text field:

    /* Keep figures and captions together if possible. Also ensure images are centered. */
    figure { page-break-inside: avoid; }
    figcaption { text-align: inherit; }
    img { margin: 1rem 0rem 1rem 0rem; }
    

    You’ll note that for img I only override the margin and leave the rest alone. This is good practice (only state what you want to change), but it won’t hurt anything to leave the “display:block” part in as well.

Give that a test compile. It should work well, and if in the future you need to use captions, you should find they work as expected, too, rather than being centre-aligned on their own.

Thank you. Much appreciated.