Reflowable ePub: Can you vertically center text?

Community Beginner ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

This would be for things like a dedication page, where there is a minimal amount of text. I've included page breaks to isolate it to its own page, but I'd like to then vertically center the content on the page. I've seen it in other ebooks but am not sure how to accomplish it.

TOPICS
EPUB , How to

Views

70

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

It can be done, but there are several hurdles. Neither EPUB readers nor Kindle Reader much like space above elements at the top of a page or handle it consistently.

 

The first problem is that reflowable format doesn't really have pages—pagination is imposed by the reader—so you have to force a new page start. The only place a new page starts, as with a web page, is at the beginning of the document. The very first item in a document, such as a book title, will allow space above it. For something further into the document, you have to force a break in the structure to get a "new document" and thus a new start and thus a "new page."

 

So create a style named DEDICATION. In the paragraph style, under Export Tagging, check the Split Document box. This will make ID split the contents every time it encounters this style. That is, it will start a new XHTML content file at this point.

 

Now add space above it — try 3 inches or 18 picas.

 

When you export to EPUB, under General, check Split Document and select Based on Paragraph Style. That will enable the document split. (There are other ways to manage document splits as well.)

 

Now, the DEDICATION style should be at the start of its own page and about a quarter of the screen page down from the top. From inside InDesign, all you can to is adjust the top spacing until it is where you want it, and it won't be dynamic with the screen size. This is usually good enough if you assume a normal screen reader size.

 

If you really want to fuss it into the middle of the page, for all readers, or some consistently similar spacing, you will have to edit the EPUB's CSS. You can go into the EPUB file and edit, but that's messy and has to be done on every export. The easier way is this:

  • Create a file using a text editor and save it as dedspace.css.
  • Put the following code in this file:
  • p.DEDICATION {
    margin-top:50vh;
    }
  • In EPUB export, under HTML/CSS, add dedspace.css to the CSS file list.

 

Export. The DEDICATION style should now be about halfway down the screen. You can tweak that margin value (it's a percentage of screen height) until the text is where you want it.

 

(That's all case-sensitive, by the way. DEDICATION and Dedication and dedication are not all the same for CSS code; use the same for the style name and the code.)

 

(Also, vh does not work in Kindle. You can substitute % [percentage] or vw, both of which are percentages of the screen width... not always useful.)

 

As I said... several hurdles. Sometimes just defining a page break (under Keep Options) will substitute for the mess of doing the document split, but the response is erratic and depends on whether a reader responds to the page-break parameter in the code. (The best standard one, Thorium, does not.) The doc-split technique is the only absolute way to force that new page in an EPUB document AND have space above.

 

|| Word & InDesign to Kindle (& EPUB): a Professional Guide (Amazon)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Jun 07, 2022 Jun 07, 2022

Copy link to clipboard

Copied

LATEST

And here's a half-ursed way to do a page break: put a large space-below value on the previous paragraph. If you have, say, a heading you want on a new page, create another style called BODY last or BODY pgbrk, and give it a large space-after value like 40 picas (about one page height is best). All bottom space will just disappear on EPUB pages, but it will force the next paragraph to appear on the next virtual page.

 

So:

  • regular body paragraph
  • regular body paragraph
  • BODY pgbrk paragraph
  • (bottom space forces virtual page break here)
  • CHAPTER HEAD - on its own new 'page.'

 

Works well enough, unless the screen reader is large and the body text is set very small. The doc-split technique is more absolute.

 

This also will not preserve ID-defined space above the following head; it will disappear. CSS padding can be used to create top spacing it in this case. (Yes, this is all convoluted!)

 

|| Word & InDesign to Kindle (& EPUB): a Professional Guide (Amazon)

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines