Remove line breaks between images when compiling

Help please! I have a series of images on the same line, looks great in the editor. But when I compile to eBook, it adds a line break between each image. Any idea how to prevent that from happening, so I can keep the images on the same line?

Combine them into a single image?

It’s very difficult to define precise formatting in an ebook, because they’re designed to resize the “page” as needed based on the device screen size and user preferences.


Sorry for the misunderstanding. No, I don’t need them to be a single image, I need them separate but each on the same line. When I put them in the editor they look like this:


But when I compile, line breaks are added so it looks like this:


Is there a way to keep them all on the same line after compile?

Yes, I understand. And I’m saying that the only way to guarantee that is to combine them into a single image.


Only problem with that is each image links to a different place…

Could the line breakage just be due to the combined width of the images exceeding the ebook page width? In which case, you might try with smaller versions of the images?

(I don’t work with the ebook format, so I am just freelancing on this.)


Unfortunately, no. :cry: The images are very small.

Generally, readers choose the layout of the books they are reading. That said, would a three-column table with inserted images work as you need it to (see sample project and ePub attached)?

Slàinte mhòr. (458 KB) (707 KB)

1 Like

This could work! Unfortunately, something weird is happening. When I try simply compiling using your project file, border lines are added… posting a screenshot for reference. Any idea why this is happening?

Doh, I should have mentioned this in my original post: Scrivener compiles with formatting that shows lines in tables. I edited the CSS post-compile in the sample ePub, removing the table formatting that referenced “solid”. I imagine it must be possible to add custom CSS to Scrivener during compile to remove any visible lines, but I didn’t bother to look at that as I was just trying to address the issue of keeping images in a single row. I imagine Ioa or Keith or a CSS wizard or customer support would be able to provide the custom CSS in an instant.

It might also be possible to arrange the images with CSS alone. It can be done for web pages using HTML and CSS, so I assume it must also be possible for ePub. Although I imagine that a table is more likely to hold its shape, if that is really what you want your book to do. … y_side.asp

I know very little about CSS, but one of the specialists should be able to help you with cleaner coding than anything that I might concoct.

Slàinte mhòr.

Some CSS to zero out borders could be something like this:

#theRelevantObjectsID {border:0px}


.theRelevantObjectsClass {border:0px}

or, I suppose,

table,tr,td {border:0px}

The first picks out a unique object by its id, the second picks out all objects in a class, and the last pegs all tables in the document – whichever is appropriate. The last is a shotgun approach, but perhaps the simplest to try, since it does not require you to know an id or class that will peg the target table. It has the downside that it will crush the borders of anything formatted with a table in your compiled output.

I would step back a bit and take a look at why the images come out on their own lines in the first place, and see if that can be solved at the source. There is nothing wrong with having more than one graphic on a line, fundamentally. HTML treats graphics much like the editor in Scrivener does—they kind of act like “letters” in how the flow around text and wrap to the width of the display.

But most images in ebooks don’t work like that, and as a result there is one line of CSS in our provided default that forces a one-image-per-line output. Thus what we are observing here is not how eBooks work by default, this is something Scrivener is doing, and if that is the case you can simply switch off that behaviour!

Let’s use the sample project provided by JoRo to start from:

  1. Firstly I drag each image out of the table, into the Binder, so that I can use them elsewhere.

  2. In the file called “2”, I add:

    <$img:1> <$img:2> <$img:3>

    (Feel free to drag in the images themselves if that is what you prefer, it’s all the same to Scrivener.)

  3. Run a test compile with the provided settings. Drill down into the “Scrivener Test/source/Scrivener Test/OPS” subfolder and locate the HTML file that has the images (Quick Look is handy here—but in this example the answer is obvious as there are no section breaks, meaning only one body.xhtml file to concern ourselves with).

  4. In your browser, with this file loaded, right-click on one of the images in the vertical column of them, and “Inspect” it (the command may be different depending on the browser). Open the CSS or “Styles” sidebar if necessary.

  5. All right, now you can see exactly which forces are influencing the image you right-clicked on. The suspicious line is here:

    display: block;

    A “block” element in HTML always falls on its own line, kind of a like a paragraph would. Ordinarily images act like letters, as I described earlier, but with this one simple CSS command we’ve told all images in the book to stop acting like letters, and start acting like paragraphs.

    Most browser have a checkmark beside each CSS line. Try disabling this line and examine the result. That’s also a very useful capability if you don’t know what you are looking for, as the results update in real time within the browser.

  6. We’ve now identified the culprit, here’s how to fix it:

    1. Edit your compile format, and click on the CSS pane.

    2. We can’t modify the CSS itself, because that is on the “Default Stylesheet” side of things. We can only edit the “Custom Stylesheet”. However given how CSS works this is no problem. We can override earlier declarations in the CSS file by adding the following line in the “Custom Stylesheet” column:

      img { display: inline; }

      “Inline” is the default behaviour for images, so we’re mainly just telling the eBook reader to ignore the earlier declaration to convert how images display, and go back to how they work by default in HTML.

You’ll want to proof other images in your project and make sure they are all working as intended. Normal figures on their own lines should be fine, including those with captions. It would mainly be a matter of any custom image uses in contexts where the image may not have been added to its own line, and you’ve been relying on this block behaviour the whole time to “correct” that problem. An image placeholder in the title Suffix field for instance, might technically be on the same line as the chapter heading, but display on its own line centred below it thanks to how the CSS works.

Now myself, I would take all of this a little further. I would put a paragraph style on the line with images, maybe call it “Image Row”. Then instead of changing how all images work, I could be much more precise about it, as Scrivener will put an HTML container around the images, named after the style:

<p class="image-row"><img src="..."/> <img src="..."/> <img src="..."/></p>

With something like that we can be much more surgical with CSS, treating images inside of “image-row” containers differently from images not inside those containers:

.image-row img { display: inline; }

So that’s something to consider if you have figures elsewhere that depend on block display (and you can’t fix them individually). It’s also something to consider if you want to do a little more with this idea. For example:

/* Supporting CSS for the "Image Row" style. */
.image-row img {
	display: inline;
	padding: 0em 0.5em 0em 0.5em;
.image-row {
	text-align: center;
	margin-left: auto;
	margin-right: auto;
	white-space: nowrap;

Because we have a container around the images, we can do stuff to all of the images collectively as well, with the CSS that targets the .image-row class by itself. With that we make sure the images are centre-aligned on the screen, and that if the screen is too narrow, they won’t wrap to the next line. As for the images themselves, we also add a little padding between them so they look nicer.

I’ve attached a copy of the sample project with these revisions made to it, in case any instructions above are unclear. (923 KB)

Ioa, that wizardry gets a standing ovation from me.

Slàinte mhòr.

Epic! Thank you so much for the detailed response! I will give it a shot asap and report back!

Absolutely perfect. This one simple line did the trick! AMAZING!!! I’m going to play with your second option as well, but for the moment, this quick fix is EXACTLY what I needed!! THANK YOU!!!

Hi, Ioa.

Dumb question. If we add extra images (as in the sample project attached), how do we get Scrivener to handle those images differently: one set of images as “block” and the other as “inline”?


Slàinte mhòr.

Scrivener (610 KB)

Having two different methods of image display, a row versus a column, would require the style-based approach I described above. In the sample project you posted, the set of test images you added has the “Image Row” paragraph style applied to it, which is the only ingredient necessary to make an inline row of images.

To have a set of images that are displayed in a column, simply remove the style. We did not override the default behaviour of all images in in the ebook with these settings, we only override how images work when they are found inside an Image Row paragraph.

The other, simpler method, of removing that default behaviour itself would mean having to do the inverse. If you want some images in a column but most in a row, then you’d want to create an “Image Column” style that specifically sets this:

.image-column img { display: block; }

Hi, Ioa.

I clearly compounded my failure to understand your original advice by then using copy and paste to carry over a style that I hadn’t appreciated existed / seen in the first place.

I get it now. Wish I had understood it in the dozen times that I read your original solution. My bad.

Many thanks, yet again.

Slàinte mhòr.

Oh no, if you had to read it over a dozen times I probably didn’t explain it well enough. :slight_smile: I probably should have put something visible on the styled text like a highlight, instead of just leaving it raw looking in the editor. I do that sometimes myself, as I prefer a rather low-key more plain-text looking editor, but I forget that can be confusing.

Not the oracle’s fault at all.

Other than trying to help others on the forum, I haven’t used styles at all, mainly because I tend to switch fonts and other settings when writing (as such changes make me see and think about work differently), which means I would wreck styles if I used them. I just use immutable MMD.

You said, “I would put a paragraph style on the line with images, maybe call it “Image Row”.”

I repeatedly read and misunderstood that part, thinking that you were styling things through CSS alone: I just didn’t think of creating or using a style in the editor initially. Your additional explanation made it clear that you had created a new style in the editor. I originally hit a blind spot and reinforced that error with each subsequent re-reading. My mistake entirely. Not yours.

Grateful for the help.

Slàinte mhòr.