Take pride in your eBook formatting (Part VII)
Posted by Guido ·Jan 21
This is the seventh installment of a series of articles. To read the previous one, please click here
As you can probably tell by now from the last installment, we are by now getting pretty close to real tangible results that you can actually use, so let’s press on without delay.
The first thing we are going to do next is to turn our previously marked up document and turn it into a valid HTML file. In order to do that, we will have to wrap our text with proper header information. Simply use the sample below and paste the next few lines into the beginning of your existing text file.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<style type="text/css">
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, pre, table, th, td, tr { margin: 0; padding: 0em; }
p
{
text-indent: 1.5em;
margin-bottom: 0.2em;
}
</style>
</head>
<body>
Once you have done that, copy the following line and insert it at the very end of your text file.
</body>
We have now wrapped your entire marked-up book text with proper HTML headers and have a valid XHTML file. Make sure to save it with an .html extension, and then load the file in your web browser. You can now already see a preliminary version of your book. You might want to resize the browser window to roughly resemble the size of an eBook reader and you will better see how the text flows on a smaller display. Exciting, isn’t it?
You may have noticed that we have the first style sheet information in our file now. It is very basic and determines only the look of the <p> tags.
p
{
text-indent: 1.5em;
margin-bottom: 0.2em;
}
Let us play with this paragraph style for a moment so you get a feel for what it does and how you can affect its results.
For example, change the text-indent value to 5em, save the file and then hit the Reload button in your browser. You should now see that the first-line indentation in your book has changed quite a bit — excessively so, I should say.
Change it back to its original value and let us adjust the margin-bottom value to 4em. Save the file and refresh it in your browser.
As you will see, we have now dramatically increased the spacing between individual paragraphs. We are on a roll. Are you feeling dangerous, yet? If so, let’s do something radical!
Change the margin value back to its original value and include the following line right underneath it.
font-weight: bold;
I am sure you know what is going to happen once we save this file and refresh it in the browser. As expected, all of your text is now in bold typeface. Pretty cool, but let’s take it up another notch. Insert the following line underneath the font-weight line.
font-size: 2em;
If you view this version in your browser, you now see that your book is in a really large, bold print. Very cool, isn’t it? Especially, since this is just how our chapter headings should look like… All we would need is a way to tell the browser, which those chapter headings are. Which gives me an idea.
Replace the paragraph style in your file with the following block.
p
{
text-indent: 1.5em;
margin-bottom: 0.2em;
}
p.chapter
{
text-indent: 1.5em;
font-weight: bold;
font-size: 2em;
}
If you remember how style sheets work, you already see what is happening. We have created a second paragraph style named “chapter” and we will be using that one to style our chapter headings.
Here is a short sample text I will be using in the following examples to show you how to massage the different parts of your eBook. It’s a little piece from my book Terrorlord from the “Jason Dark: Ghost Hunter” series, in case you’re curious. As you can see, the example has chapter headings and I have wrapped them with a parametrized paragraph tag. As a result the browser will use the chapter style to render the text between these paragraphs, while using the standard paragraph style for the other text blocks.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<head>
<style type="text/css">
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, pre, table, th, td, tr { margin: 0; padding: 0em; }
p
{
text-indent: 1.5em;
margin-bottom: 0.2em;
}
p.chapter
{
text-indent: 1.5em;
font-weight: bold;
font-size: 2em;
}
</style>
</head>
<body>
<p class="chapter">CHAPTER 1</p>
<p>Jason Dark was leaning over the chess board when Siu Lin entered the room with a dog-eared book in her hands.</p>
<p>“Trying to solve another one of the London Illustrated’s chess challenges?” she asked.</p>
<p class="chapter">CHAPTER 2</p>
<p>She had a smug smile on her face when she finally looked at Dark, but it disappeared the moment she saw his expression.</p>
<p>Dark had gone entirely pale as all blood seemed to have drained from his face. For a moment his eyes stared straight ahead, unfocused, not seeing anything. His lips were trembling and he clutched his left arm.</p>
<p>***</p>
</body>
This may all look a little garbled right now, because of the blog layout, but feel free to copy this and save it to use it as your sandbox playground, if you wish. If you load it up in the browser, this thing starts to look like a book, actually, doesn’t it? And it will only get better from here.
When we start a new chapter in our book, we usually want it to start on a new page, and styles can help us do that. Insert the following line in the chapter paragraph style.
page-break-before: always;
Unfortunately, web browsers do not handle page breaks properly — traditionally, there are no page breaks in web pages — so you won’t see them when you preview your book right now. If we were to load it onto an eBook reader, though, it would work. Right now you will just have to take my word for it.
Page breaks are nice and all, but usually, we would not want the chapter heading to be right at the top of the page. It should be moved down a little, leaving some white space around it, at the top and at the bottom. Very easy exercise, really. All you have to do is insert the following to lines in the “chapter” style.
margin-top:5em;
margin-bottom:2em;
Save it and refresh your browser, and you will see that you now have nice, clean spacing around the “CHAPTER 1” and “CHAPTER 2” headings in our example. And all of that without really changing your actual book text itself.
We’re doing it all through styles, which means if you think the white space is a bit too much, all you have to do is change the style values and it will automatically affect all your chapter headings throughout the entire book.
Now, you may have noticed the three stars at the end of my eBook source file. I will use these for another specialized styling, because I want these three stars to be centered on the page, something you will encounter in most books at one point or another. Someone versed in HTML would probably go about and simply wrap these stars with <center> and </center> tags. Sadly, that’s a bad idea when it comes to eBooks.
Centering text in eBooks is one of the most error prone undertakings because device manufacturers seem to have different takes on what “centering” means. Sounds ridiculous, I know, but I am not lying to you.
To create foolproof centering we have to double-stitch our approach, to make sure every device understands exactly what it is we’re trying to do.
First we will include the following two styles in our file.
p.centered
{
text-indent: 0em;
text-align: center;
}
span.centered
{
text-indent: 0em;
text-align: center;
}
Since both declarations look identical, this might seem redundant, but sadly, some devices, like the iPad, require the <span> tag for centered elements, while others require the more commonly used <p> tag. I think it is also important to point out that the text-indent: 0em; setting is important in this context. Without it, the device would actually render our text slightly off-center because it would center the text and then add a 1.5em indentation to it. Not what we want, so we have to reset the indentation to zero.
To center our text line, we will now wrap it with the proper HTML tags and make it look like this.
<p class="centered"><span class="centered">***</span></p>
This may not look nice in code form, but it solves all our problems and the line will now be centered correctly on all devices I have come across. I am enclosing here a little preview, roughly what the example looks like with all our little improvements in place.
CHAPTER 1
Jason Dark was leaning over the chess board when Siu Lin entered the room with a dog-eared book in her hands.
“Trying to solve another one of the London Illustrated’s chess challenges?” she asked.
CHAPTER 2
She had a smug smile on her face when she finally looked at Dark, but it disappeared the moment she saw his expression.
Dark had gone entirely pale as all blood seemed to have drained from his face. For a moment his eyes stared straight ahead, unfocused, not seeing anything. His lips were trembling and he clutched his left arm.
***
In all of this, you may have noticed that I did not set any default font face, size or text justification. This is not an oversight, let me tell you. I did that on purpose.
eBook readers allow users to use their preferred settings. Font size, justification and font type are very personal things and who are we to mess with what people like? By not setting our own values, the eBook device will automatically fall back onto the user preferences and immediately display our book in the user’s preferred way. It may be a small thing, but trust me, it goes over really well with your readers. Usability is key!
Go ahead now, and make the proper adjustments to your own book file. Mark up your chapter headings and the centered text portions, adjust the styles to your linking and take a look at your own book. As you may have noticed, it has already turned into a pretty reliable and predictable thing. Let me stress again at this point, that this is the reason why you do not want to export your eBooks straight from a word processor. See, how much control you have over the look and feel of your book with just a few simple steps? And it only gets better…
In the next installment we will add still some more frills to our book and then in the not too distant future, go to the next step, building the actual eBook in Calibre.
Part I • Part II • Part III • Part IV • Part V • Part VI • Part VII • Part VIII • Part IX



69 comments
Comment by Deb on January 23, 2011 at 2:21 pm
Waiting….
. I’m working a short story through right now, just to get some practice. I think I’ll brave the world of importing it to Calibre myself for now. Eagerly awaiting the “frills” installment.
Comment by Kathy on February 12, 2011 at 4:42 pm
How do you load the html file into your web browser?
Comment by Guido on February 12, 2011 at 8:10 pm
The easiest way is to simply double-click it. The other way is to open your browser and then in the “File” menu, select “Open File.”
Comment by Glenn McCreedy on February 13, 2011 at 8:02 pm
Wow, it is so true that CSS is the way to go. Set it and let it roll. The reader’s experience is paramount so give the reader the control and flexibility inherent in the device, facilitated by the publisher’s formatting. I love it you have taken into consideration the different needs of devices and formats.
Comment by Patrick Samphire on February 14, 2011 at 1:33 pm
Hi Guido,
I’ve been reading this series of posts with enormous interest. Thank you. It’s fantastically clear and helpful, and you make the whole process seem very easy.
I had a question about the html sample you give above. The html isn’t valid in that it doesn’t have an html tag and it doesn’t have a title tag. I’m wondering if that’s an oversight or if it’s necessary for the process of making ebooks.
Thanks
Comment by Guido on February 14, 2011 at 3:02 pm
Patrick, that is actually deliberate. I haven’t entirely read up on why that is, but if you include the actual tags Calibre has problems converting it into a proper eBook file.
Comment by Patrick Samphire on February 15, 2011 at 1:44 am
Thanks!
Comment by Larissa Lyons on February 26, 2011 at 3:48 pm
Guido – Hi. Whew! I’m finally working through all your fabulous posts & learning a ton. This is my first exposure to css; thanks for making it (relatively
) painless. A question for you: I want the chapter headings centered but I’m not sure how to go about combining the p.chapter class with the two on centering. Can you please point me in the right direction? Thanks!
Comment by Guido on February 26, 2011 at 4:52 pm
Larissa, the easiest way to do it by using multiple parameters for the style. It would look something like this
<p class=”chapter centered”><span class=”centered”>CHAPTER 1</span></p>
Tagging it like this will first use the “chapter” paragraph style on the text and then also the “centered” paragraph style.
Comment by Dave Atkinson on July 4, 2011 at 10:24 am
Hi Guido
Enormous thanks for your efforts in putting all this together. However I’ve got a problem. Using your sandbox sample above (my material gives the same error) neither Firefox nor Chrome will accept the code as valid. The error is: “This page contains the following errors:
error on line 19 at column 1: Extra content at the end of the document
error on line 19 at column 1: Encoding error
Below is a rendering of the page up to the first error.
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, pre, table, th, td, tr { margin: 0; padding: 0.1em; } p { text-indent: 1.5em; margin-bottom: 0.2em; } p.chapter { text-indent: 1.5em; font-weight: bold; font-size: 2em; }”
Can you throw any light on this?
Thanks, Dave
Comment by Guido on July 4, 2011 at 12:07 pm
Dave,
There are a couple of errors in the text you pasted. Hard to tell if it just happened because you copied it over and it was reformatted, or if it’s in your text.
Send me your file as an email and I’ll be happy to take a look.
Comment by Dave Atkinson on July 7, 2011 at 9:33 am
Guido -
Found the problem myself – red face day…….!
Thanks anyway,
Dave
Comment by MoJo on July 19, 2011 at 5:40 pm
This is great so far, great info and wonderfully over explained, which is exactly how I like it. Too many people expect you know everything and they think you should get it from the jump. Love the way you break it down and show why things need to be done in a particular way.
One thing. I got stopped on the last two pieces of code you were talking about. The center – center span and ***.
For me, I really didn’t know where to put it and had to knock around about to get it to work, I guess I got it to work, it looks right but being green with HTML, I’m not sure.
Suggestion: At the end of each section, maybe the mark up of all the code discussed in the correct placement, (as you do with your 2 chapter example code) so we can see we are doing it right. This might be asking too much but it would help to know I am placing the code correctly. I’m thinking more for others who come here to glean your expertise as I feel I will have it before too long.
Thanks for the great work Guido, just great.
Comment by Cora on July 25, 2011 at 7:49 pm
First of all, thanks a lot for this great guide. It has been enormously helpful in formatting my e-books.
However, I have run into a slight problem on my most recent project, which includes a few lines quoted from a (fictional) newspaper article. I want to set the article visually apart from the main text.
I assume that this is done via style, so I created separate styles for the newspaper headline and text. However, I want to indent the entire newspaper text, whereas the style only indents the first line of a paragraph. Any idea of how this could be achieved? Does the
Comment by Cora on July 25, 2011 at 7:50 pm
Oops. I still don’t know whether the blockquote tag – cause that’s what meant – works for e-readers, but it obviously works for comments.
Comment by Guido on July 25, 2011 at 8:24 pm
Cora, you should use the margin-left attribute to indent an entire block of text, like your newspaper article, somewhat like this…
p.article { margin-left:2em; text-indent:0em; }
Comment by Cora on July 25, 2011 at 9:59 pm
Thanks. I’ll try that.
Comment by Mark on August 25, 2011 at 3:30 pm
Sigil does a great job of importing and validating html. The developers put a lot of work into making sure the finished ebook complies with the ePub standard.
http://code.google.com/p/sigil/
Comment by Guido on August 25, 2011 at 4:15 pm
Yeah, but as I pointed out before on many occasions, word processors make for poor e-book formatters, usually. While they do output ePub files, their quality is generally dubious at best.
Comment by Mark on August 25, 2011 at 7:31 pm
Sigil isn’t a word processor. I’ll shutup now.
Comment by Guido on August 25, 2011 at 7:32 pm
Ah, sorry, my bad. I remember I looked at it a long time ago and didn’t like it, but it may have been that I simply didn’t spend enough time with it.
Comment by Jane on August 26, 2011 at 8:48 am
Guido, before asking my question I’d like to say how much I appreciate your making “Take Pride” freely available. I have some knowledge of html and css, but have found your detailed hand-holding extremely helpful. I have read through all nine parts twice now, and found other people’s comments and queries, and your replies, useful too.
I am just embarking on the ebook formatting of an epic-length poem for my partner. Every line – and there are thousands of them! – (apart from links to other poems) is centred. (Whether the links will work or not is perhaps another question…) I have wrapped every stanza in a pair of paragraph tags (these are centred via a separate style sheet), and used line breaks for “carriage returns”. Then I read above about “double-stitching” and the advisability of wrapping centred text within span tags as well. Gulp!
So, I need to ask, firstly, are my line breaks permissable within a span, so I only need to add one pair of span tags per stanza (as opposed to each line)? Secondly, whichever way I need to add the span tags (per paragraph or per line), do you know of a quick way to do it?
I hope I’ve explained this clearly enough, and that they’re not stupid questions. Some of your supportive hand-holding would be very welcome!
Comment by Guido on August 26, 2011 at 11:27 am
One span per stanza will work just fine. Line breaks are permissible within spans. That’s what I do often to cut down on code size. Since you say, the entire book is a poem, the fastest way to add the span to all stanzas would probably be to search and replace all occurrences of your opening <p class=”stanza”> tag with something like <p class=”stanza”><span class=”centered”> and the do the same thing with the closing tags where you replace all occurrences of </p> with </span></p>. That should do the trick for you in a matter of seconds.
Comment by Jane on August 27, 2011 at 12:19 am
I’m very relieved! Thanks so much for your helpful, reassuring and prompt response.
Comment by Terry Simpson on September 29, 2011 at 3:39 pm
Stayed up last night learning this and formatted my book. Wonderful results. On the normal apps, digital editions etc all shows well, but on one app (Moonreader) that I use on my tablet and my phone, my chapters aren’t showing formatted and centered. They instead appear at the top left without any formatting. Any particular reason?
Comment by Guido on September 29, 2011 at 3:45 pm
I’ve never heard of Moonreader, so I’m not at all familiar with it. If it is the only one with issues, however, the odds are that it is a software bug on their end. Still, it might be worth investigating.
Comment by Nicki on September 29, 2011 at 4:10 pm
Hi Guido,
I have followed your instructions for a couple of eBooks now and have found it very helpful. I pasted the style setup you presented in this series and added extra styles as needed.
I just wanted to report that I’ve had a big problem with the padding, which was set here:
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, pre, table, th, td, tr { margin: 0; padding: 0.1em;
On Kindle (via Calibre) the entire text of the eBook is substantially indented, I didn’t notice this on HTML or the Kindle PC app but to my dismay it is very obvious on an actual Kindle (I only just bought one). I did notice it was indented in the KDP preview window, but I thought it was an error with the preview software as I was so sure my html was squeaky clean after following all these steps to the letter. Can you comment on the reason for including this padding?
Comment by Guido on September 29, 2011 at 5:17 pm
I thought I posted this here before, but it may just have gotten lost. Change the reset line to this
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, pre, table, th, td, tr { margin: 0; padding: 0em; }Unfortunately the Kindle handles neither em-spacing nor right margins and padding correctly, so yes, you do not want to add all-around margins.
Comment by Marie Loughin on October 1, 2011 at 4:38 pm
Hello Guido,
I’ve included some poetry in my novel and would like to prevent page breaks in the middle of a stanza. Is that possible?
(Like everyone else here, I’ve found your advice extremely helpful. I’m thinking of naming my next cat after you (since I’m not having any more kids).)
Comment by Guido on October 1, 2011 at 5:11 pm
Hahaha, Marie, naming a cat after me. that is priceless.
Thank you.
There is no way to prevent a page-break in a stanza, per se. If the screen ends, well, then the screen ends and the text needs to be broken onto the next page. The only thing you could do is to start the poem on a new page so that you can be certain it won’t have to wrap to the next page – unless it is too long to fit on a single page, of course. Unfortunately, there is a possibility, that this creates a pretty empty page just before the poem, which is also very unsightly. So you will have to chose what you consider to be the lesser of the two evils.
Comment by Marie Loughin on October 3, 2011 at 10:30 pm
Huh! That surprises me! Thanks for the response. I won’t spend any more time trying to figure it out.
Comment by Tina on October 19, 2011 at 7:05 am
I seem to be having trouble getting chapter headings centered. I’m using the tag you posted above for Larissa:
CHAPTER 1
and it centers the text but does not apply the chapter formatting (bold type, larger size, etc). I’m assuming I need to do something else in the style sheet to combine the two parameters, but I haven’t figured it out. Any tips? Thanks.
Comment by Tina on October 19, 2011 at 8:11 am
Never mind. I think I figured out the chapter centering.
I do have another question, though- if I have a title page, copy right page, and acknowledgements before chapter 1 of my book starts, and I want each of them on a separate page, how do I insert that page break before each one?
Comment by Guido on October 19, 2011 at 10:26 pm
If this does not work, then there is something wrong with your code. The way I posted it for Larissa is how you apply multiple styles to a tag. You have to make sure, however, that one style is not overwriting the other.
If, for example, one style sets the font to bold and then the other one sets it back to normal, evidently, you have a problem.
If all else fails, feel free to email me your HTML file and I’ll take a look.
Comment by Guido on October 19, 2011 at 10:29 pm
To create page breaks you should create a special style for that, like the one I am printing below.
p.pagebreak { page-break-before:always; }In your HTML section you ca now say something like this
<p class="pagebreak centered"><span class="centered">Acknowledgements</span></p>Comment by Mark on October 26, 2011 at 5:32 am
For Kindle the mobi tag will also work for page breaks. I wasn’t aware that page-break-before:always works too. It’s a much cleaner solution.
Comment by Mark on October 26, 2011 at 5:34 am
… the mobi tag mbp:pagebreak within angle brackets (last preceded by a slash) …
Comment by Mickey B on November 17, 2011 at 1:01 pm
Is there a way to make all chapters centered in an html doc? Seems like you are showing how to do it on an individual line but what could you add in the chapter style section:
p.chapter
{
text-indent: 1.5em;
font-weight: bold;
font-size: 2em;
to make it work for the whole thing, maybe you said it and I am just not seeing it. Maybe this is not a desirable method for some reason.
If you or anyone else can answer this, please let me know.
Wonderful guidance Guido.
PS: I had too many typos in my previous post, I rewrote it so it would make more sense.
Comment by Guido on November 17, 2011 at 1:34 pm
I am not sure I understand what you are trying to say. Are you asking a question or making a point?
Comment by Mickey B on November 18, 2011 at 12:16 pm
I was asking a question. It could be I just don’t know enough to ask it correctly.
In the part VI you mentioned dealing with chapter heading later on in the tutorial.
In this part VII above, you go into some detail about Chapters but in reference to your page mockup. In that mockup you have your chapter wrapped like so.
<p class=”chapter”>CHAPTER 1***Chapter 1</p>
So my questions are:
Q1: Is this wrap in the ballpark of correct?
Q2: Is there a way to change all my Chapter * headings with the correct tag wraps, like you did with search ^(.+)$ and replace with \1 for paragraphs?
Q3: Is there an easier way to do that type of centering in the p.chapter style section?
Q4: Or is it best done in Calibre for some reason?
I know this is a mouthful and I hope you don’t find it too annoying. I’ve learned so much reading this tutorial, I can’t thank you enough.
I guess I’m trying to really understand the style sections, as apposed to adding a new P section, like you did with:
p.centered
{
text-indent: 0em;
text-align: center;
}
span.centered
{
text-indent: 0em;
text-align: center;
}
I feel like I almost have the basics and that is a huge step. Thank you G.
Comment by Mickey B on November 18, 2011 at 12:18 pm
Sorry Gudio, it’s not writing all the code examples I wrote in the first comment… Actually, if you can delete all my comments, I’ll try again later when I can figure out how to post code and have it no execute…
Man, this is frustrating.
Comment by Mickey B on November 19, 2011 at 4:29 pm
OK, let me try again.
The centering issue:
Is it alright to use
text-align: center;
in a style, like say p.chapters
or is that a mistake and must I use p.centered as a style and a P class=center wrap on everything I center in the book or is that just for images?
About Table of Contents:
I also had a question about TOC, at this point I did it manually using “a href=”#C1 , #C2 , #C4 etc. (I didn’t write it all out cause I don’t know how to do that with having the browser execute the code) I wanted to know if this is going to work and if it’s even worth it. I wanted to make sure the book was searchable.
Question about Margins and Padding: { margin: 0; padding: 0em; }
About the reset, wondering if Kindle and Nook add margins anyway or is it something that has to be done in the code? Like in the p style or each individual p class?
About Images:
I saw how you went about adding images to the book as chapter doodads, and I assume they have to be in the same folder to make them work for Calibre or anything else for that matter. However, does it make any sense to add the cover image before you do any converting or is it best to let Calibre do it. I was also playing with the idea of trying my hand at Sigil, do you know anything about the program?
Again, I want to thank you so very much, I know tons more now than I ever would have without you. This is a great set of tutorials and I will forward to supporting you in your future endeavors. Thanks again.
PS: Sorry about all the messed up posts, hope to see them disappearing soon.
Comment by Guido on November 19, 2011 at 5:07 pm
Whether you can automate the process of centering and wrapping all your chapter headings depends on your manuscript and if you have something that marks your chapters uniquely so that it could be searched. If all your chapters are called “Chapter One,” “Chapter Two,” etc for example, you can do an automated search and replace using a Regular Expression like this, for example…
Search for
<p>Chapter (.*?)</p>Replace with
<p class="chapter"><span class="centered">Chapter $1</span></p>This is just an example, of course, and ultimately, it depends on your text formatting etc. how this search would exactly have to look like.
The centering can be part of any style. But you will have to also include a span tag that centers in order to properly center things on all devices, like I’ve described in the tutorial.
You can hand-code a TOC, yes, but why would you? Calibre has a way automate the process for you, so you can save all that time setting anchors in the text and cross linking them and let the software do it for you.
The displays on devices usually have a certain built-in margin that is defined by the hardware, yes. Even if you set the margin to 0 by default – which I always do – there will be a small margin.
As for images, the cover image does not go into the HTML file. It is part of the meta-data that you set up in Calibre.
I have played around with Sigil, yes, but I do not like the way the software is laid out. I find it needlessly cumbersome, but that’s just me. I’m very happy with my toolchain and there’s no really need for me to make any changes to it.
Comment by Mickey B on November 19, 2011 at 6:11 pm
That chapter replace code is very helpful. That is something I have to learn much better.
Centered:
So is either centering better than the other? I had assumed it would take more code to wrap each heading (file size) with the center class, than having the centering done inside the p.chapter style. Is there a reason NOT to have it in the p.chapter style?
Also: how would you go about adding span.centered into the p.chapter style, (assuming this is not a bad idea or can be done at all) since the way you have it written is in it’s OWN style, not sure how I would go about adding it under p.chapter?
Under p.centered and span.centered styles they have the same instructions
text-indent: 0em;
text-align: center;
So I assume having
text-indent: 0em;
text-align: center;
under my p.chapter style takes care of the normal centered (maybe I an wrong) but is there any way to add the span version as well, under the p.chapter style?
As for all the other info in your post, I got it completely. Very, very helpful. You’re a coding deity! I’m so very grateful, I have to get you a free hard copy of the book.
Comment by Guido on November 19, 2011 at 11:27 pm
No, there is not way to combine them. You will have to code them separately because they are separate tags.
You can add the centering information in your chapter p tags, of course, to create something like this
p.chapter{
font-size: 2em;
text-indent: 0em;
text-align: center;
}
But you will still need to add the span tag to make sure the text will be centered properly on every device.
<p class="chapter"><span class="centered">This is the text</span></p>Comment by Mickey B on November 20, 2011 at 1:51 am
You the man G… Thank you kindly or should I say… Kindlely.
Comment by Josh Irving on December 13, 2011 at 3:52 pm
Hi Guido,
I wonder if you can help me with this…
I have a book I am working on and want to insert a line space after some italic text that immediately follows each chapter heading.
Is there a quick way to accomplish this?
Thank you so much for this super helpful and comprehensive guide.
All best,
Josh
Comment by Guido on December 13, 2011 at 5:08 pm
That depends on the way your manuscript looks like. My first choice would be to change the style for the italic text to add some extra space to it with the margin-bottom setting. That way you have to make one change and it affects the text throughout your book.
Alternatively, you can do a search and replace and simply insert an empty paragraph after the italic text, like this.
<p> </p>
Comment by Josh Irving on December 14, 2011 at 9:18 am
Thank you so much Guido.
I have 16 books to do, most of my Dad’s (Clifford Irving) books that we are launching on Kindle shortly.
Cheers
Comment by Guido on December 14, 2011 at 11:43 am
Wow, that’s quite a catalog. If you need help, feel free to let me know.
Comment by Josh Irving on December 17, 2011 at 10:11 am
Hi Guido,
I attempted to create a ‘workflow document’ from this long article. With all the steps documented line by line.
It kind of works, do you have any suggestions for that? Obviously I understand that the obvious suggestion is to go with your professional formatting services. But with all these books it’s not really an option
I do like your approach as it lends itself well to may output formats.
Thanks,
Josh
Comment by Guido on December 17, 2011 at 10:30 am
I agree, Josh, it is very flexible and reliable across formats. what you see here is, in essence, the exact process I use for all my clients eBooks. Over time I have, naturally, found a few things that lent themselves to optimization and I picked up a few more tricks along the way, but overall, this is the process.
Comment by Josh Irving on December 17, 2011 at 11:28 am
I have one (or possibly two) book/s that I would like you to format, it has many pictures. Can you email offline so I can get a quote from you?
Thanks,
Josh
Comment by Beth on December 19, 2011 at 7:16 pm
Hi. I really want to thank you for the information you’ve compiled here. I like to learn and do things for myself, so your blog has really been helpful.
I have one issue that I haven’t been able to figure out, though. In the p style sheet for the paragraph style, I changed my margin-bottom to 0em because I don’t like the extra spacing between my paragraphs in the chapters. However, in certain sections, such as the title page and the copyright page, I want extra spacing between paragraphs.
I’ve checked the comments above and may have missed the answer, but here’s my question: Is there another style sheet I can create specifically to add spacing between certain paragraphs?
Thanks again for the great information.
Comment by Josh Irving on December 28, 2011 at 1:55 pm
Hello Guido,
I trust you had a good Christmas break!
I have a question that you might be able to help me with if you’re back:
I am attempting to create a TOC using the first few words of a paragraph as the heading. So I’d like to keep the target words on the same line as the rest of the paragraph. So for instance in this paragraph the target words (and TOC listing) would be “I am attempting”. I may want to bold the words. I tried using a chapter style but it is not inline as want.
How can I do this?
Thanks,
Josh
Comment by Guido on December 28, 2011 at 2:38 pm
Use the SPAN tag instead. It allows you to style words and fragments within a paragraph.
Comment by Josh Irving on January 2, 2012 at 5:42 pm
Thanks Guido,
Did you get my email, regarding a quote?
Also I am having a problem with this formatting, no matter what I do using a .MOBI format never seems to respect paragraph spacing and is always spaced out after all paragraphs.
The only way I have been able to get rid of spaces after paragraphs is to use Calibre to remove all spaces and then use to put them back where I want.
This obviously is not correct. But I have tried repeatedly and not been able to control spaces with CSS rules?
Any ideas what I’m doing wrong?
Thanks,
Josh
Comment by Guido on January 2, 2012 at 5:57 pm
Josh, I did not get any email from you. I am not sure what problem you’re having but I’d suggest, you simply email me your HTML file and ‘ll take a quick look. I sent you an email so you have the correct email address to contact me at.
Comment by Tarin on January 3, 2012 at 12:15 pm
Guido can I please email you my html thing I am obviously not getting this centering thing at all, perhaps you can see what I did wrong?
Comment by Guido on January 3, 2012 at 12:27 pm
Absolutely.
Comment by Josh Irving on January 7, 2012 at 10:33 am
Guido to the rescue…again!
I had been having problems with my CSS rules not working, this went on for weeks until I asked Guido, who found the answer
I had made a cheat sheet out of the guidelines in these pages on a SPREAD SHEET!
Be very careful as copying and pasting from a spread sheet can introduce error spaces (empty or other non regular or tab induced spaces) in front of the CSS rules. Between the left most margin and the first Curly bracket or brace. This had the effect of breaking by rules.
You have been warned!
Thank you so much,
Josh
Comment by Tarin on February 27, 2012 at 3:16 am
Hey Guido, I hope you are keeping well. I was wondering, about line spacing, everything appears on calibre has double lined space, it kinda makes stanzas for poetry look odd, is there a way for me to change the line spacing?
Comment by Guido on February 27, 2012 at 7:56 am
That depends solely on your formatting, Tarin. If you have line spacing between paragraphs and each line in your stanza is a paragraph, that will space it apart. Try to either use a separate paragraph class for the stanza or do your line breaks using the <br/> tag so that the entire stanza is a single paragraph.
Comment by Tarin on February 27, 2012 at 11:02 am
Could you please give me an example of what you mean for the stanza so I can see. Sorry if am being a dummy again. What’s the /br thing etc please?
Comment by Guido on February 27, 2012 at 12:01 pm
<p>This is the first line<br/>
This is the second line<br/>
This is the third line<br/>
And this is the end</p>
Comment by Patrick on April 29, 2012 at 5:53 am
Hello Guido,
Amazing guide that should be published as a book. I’ve read other guides –and paid for them– and they simply do not compare.
I really enjoy the emphasis on clean coding, and the clean, clear writing. Every time I read your guide, I find a little gem of coding and of inspiration.
Question 1: Should the
”
<!DOCTYPE…"
be before the tag?
In the above example, it is before the tag.
Question 2: To be sure I am understanding centering correctly, for anything we wish to center, be it text or chapter titles or images, we should use:
what ever it is
(Actually, since my short story has quite a few images, and since I want some space around my images, I have created an
my image< for my images with the following code:
p.image {
text-align: center;
margin-top: 0.6em;
margin-bottom: 0.6em;
}
span.image {
text-align: center;
margin-top: 0.6em;
margin-bottom: 0.6em;
}
Thanks again for a magnificent guide.
Comment by Patrick on April 29, 2012 at 6:45 pm
Much of what I attempted to post was cut out/dropped –for some reason much of the code was dropped– making the questions… senseless:
Restating them simply: Question 1: Shouldn’t the DOCTYPE code be before the HTML tag, not, as shown above, before the HEAD Tag?
Question 2 is not a question but a clarification (mainly for myself) that all centered items, be they paragraphs, images, headings, etc., should be contained in both p class centered, span class centered tags.
Most importantly, I wanted to say how impressed I am with the guide.
Comment by Patrick on April 30, 2012 at 12:10 pm
My mistake!
The DOCTYPE code is placed exactly as shown, before the HEAD tag.
I saw an example, on W3School, of an HTML page having the DOCTYPE before the HTML tag, and assumed incorrectly that the XML DOCTYPE would be placed in the same location.
Comment by Jack on May 4, 2012 at 1:07 pm
Guido,
Thanks so much for doing this. I’ve learned a great deal from reading your posts, but somehow I’ve lost my text indent which I set in the style as 1.5 as you suggest. By the time it gets to the body of my story, the lines are all flush left. What am I missing? I’ve tried for a couple of days to figure this one out, but there must be something very simple I’m overlooking.
html, body, div, h1, h2, h3, h4, h5, h6, ul, ol, dl, li, dt, dd, p, pre, table, th, td, tr { margin: 0; padding: 0em; }
p
{
text indent: 1.5em;
margin-bottom: 0.2em;
font-weight: bold;
font-size: 2em;
}
p.title
{
font-size: 2em;
font-weight: bold;
margin-top: 5em;
}
p.chapter
{
text- indent: 1.6em;
font-weight: bold;
font-size: 2em;
margin-top:5em;
margin-bottom:2em;
page-break-before: always;
}
p.headline
{
text-size: 1.5em;
text-weight: bold;
}
p.centered
{
text-indent: 0em;
text-align: center;
}
span.centered
{
text-indent: 0em;
text-align: center;
}
KLONDIKE JUSTICE
by
Jack R. Stanley
Lanky Ed