Join Gabriel Powell for an in-depth discussion in this video Formatting tables, part of Creating Ebooks with InDesign CS4 or CS5.
Tables are great for systematically displaying all types of information and the ePub file format has good support for them. But when you've exported an ePub file from InDesign any table formatting that you've applied to your tables is lost. Fortunately the structure of the tables is preserved. So, to format a table in an ePub file, you just have to edit the CSS file within it. In this lesson I'm going to demonstrate how I created this table. I'll switch over to InDesign and show you how it's done.
Now to expedite the process of formatting this table, I've already applied paragraph styles to all the text within the table. I applied the paragraph style called Table Title to this text within this first row. And then to all the text within the second row, I applied the paragraph style called Table Header. I applied the paragraph style called Table Body to all of the text in these cells, and then I applied Table Body Left to all the text in the left-most column.
I applied Table Body Right to all the text in the right-most column. It's also important to apply table styles and cell styles to the table. I have already applied table style called Standard Table to this entire table and I have applied a few self styles as well. So, I applied the title self style to this first header row. I applied header self style to the second header row and then I applied body cells to the rest of the cells in the table.
Notice that every other row, in this table has a shaded color applied to it. This formatting is actually applied at the table level, instead of to the individual cells within the table. So, if I go back to the table style and double click it, here within the fills category, you can see that I've applied an alternating pattern, to every other row. But in order to easily add this same color, to these rows within the ePub file, I need to apply a specific cell style to them.
So, I'll go ahead and duplicate this cell style. I'll just drag this style to the Create New icon at the bottom of the Cell Styles panel, and release the Mouse button. That creates a duplicate. Now I'll just rename it. I'll call this Body Cells Shading, which means that I should also rename this other style, so I'll call this Body Cells Normal. All right. So, now I need to apply the Body Cells Shading cell style to all of these rows. Since I've duplicated the style, none of the formatting in my table actually changes.
I'm simply tagging these rows. So, all this work that I've done within InDesign, has set me up to more easily format the table in the ePub file. So, let's go ahead and do that. I'll export the ePub file from the File menu, I'll choose Export for and then ePub. I like to view the eBook after exporting it. And within the Contents category, I want to deselect Include Embeddable Fonts and Preserve Local Overrides. I'll go ahead and click Export, so here's the table. None of the table formatting has been preserved, but the structure of the table has been preserved, and so has the text formatting.
You can see that the table title is still white which is why you don't see it, and you can see that the text is still correctly aligned. Over here in the right most column, the text is right aligned and in the left most column its still center aligned. So, the next step is to open up this ePub file and format the table. I'll go ahead and open up this ePub file into Oxygen. At the top of the Archive Browser panel I'll click the Open Archive button. Locate the ePub file, and open it up.
And then, within the OEBPS folder, I'm going to locate that XHTML file that was generated, and open it up. So, that table that I exported from InDesign, is now being structured using XHTML markup. All the information in the table is being contained within this poutermost table element. And then within this element, notice that there's a T-header element. This is my table header. My table header contains two rows.
So, here's the first row, that's what TR stands for. And here's the second row. Each row contains cells. So, that's what a TD tag is. It defines a standard cell. And then, within each TD element is a P element, which contains the actual text in the cell. And then down here a little ways is the T body, which is the main body of the table. Notice that the table element has a class attribute of standard table.
This was generated, based on the name of the style that I applied, to the the Table and InDesign. And notice that each TED element has a class attribute as well. These were generated based on the cell style names that I applied to those cells. And each P element has a class attribute as well. And these were generated based on the names of the paragraph styles that I applied to the text. So, since the structure of this table has already been created and the class attributes are already correctly applied the only thing that I actually need to do is open up the CSS file.
And edit the CSS rules in order to format the table. I'll go ahead and close this file and open up the CSS file. So, all the CSS rules that were created for the table and cells, are located at the bottom of this file. Here's the rule for the table itself, Standard Table and here are the four rules for the various cells within the table. These are empty right now, so I just need to define their formatting by adding properties to them. I'll enter a new line, and the first thing that I'd like to define is a background color for my first header row.
So, I'll type in background followed by a colon and then color. Now I could choose from one of the colors in this list of predefined colors, but I already took note of a hex value that I'd like to use instead. So, I'm going to type in the pound symbol, followed by a capital letter BA. 1E2A, and now I'll press Enter or Return. I'll go ahead and save this. Let's take a look at the results so far. I'll hide Oxygen, and I'll hide InDesign as well, and now I'll just double click this ePub file to reopen it.
And as you can see, the background color now appears behind the text in this first header row, but the text is touching the edges of the cell. So, to fix that, I need to add some padding to this CSS rule. I'll go ahead and type in padding, and I'll make that about five pixels, PX for pixels, I'll save that. Let's view the results that's looking much better. So, now I'll define the border around the next header row. I'll go ahead and go back to Oxygen.
I'll start by defining the border color. And again that's a hex value, which is 6F4F2C. In case you're wondering how I got those hex values, Mac OS 10 ships with a wonderful utility called the digital color meter, which you can actually find within the utilities folder. And I used the digital color meter to discover what those colors were. Now if you don't have that tool, you can use Photoshop to discover what the hex value of color is.
Okay, so now that I have defined the color, I'm going to define the border style which should be solid. And then the border width, which should be one pixel and I'll just go ahead and add the same padding value that I added to the first header row. Alright, I've saved the file, let's review the results. So, as you can see, a border has been applied to each cell. And notice that there's spacing between the cells. Now I need to turn that off.
So, to do that, I'm going to go back to Oxygen, reopen that XHTML file, locate the table element, and then I need to add another attribute to this element. And that attribute is cell spacing, that should have a value of 0, to turn off the cell spacing. I'll save that, and if I hide Oxygen, and double click the ePub file. You can see that I've removed the spacing between those cells. And it's looking much better now.
So, now all that's left is the formatting for the normal body cells and, the body cells that have shading. I'll go ahead and format the normal table cells first. I will just copy all of these properties from the table header I have defined. And paste them, into the body cells normal rule because I know I want those too look the same.
Reopen the file, and as you can see only those rows to which the body cells normal style was applied to have been formatted. So, I need to add that same formatting to the body cells shading rule. I'll just paste those properties in, save the file and the table is almost complete. Next I need to add shading to every other row.
So, I'll go back to Oxygen, and that's quite easily done. By adding a new property to the body cells shading rule, and that would be a background property. And the color that I'd like to apply to those rows is E7E0D9. So, that should finish my table. Alright that's really looking good, there's only one thing that I'm noticing that I'm not liking too much. And that's that this outer most stroke or boarder is thinner that the inner boarders.
And that's because the borders within the table are teaming up to create a slightly thicker border. So, to work around this, I'm going to add a border around the entire table itself. So, to do that, I'm going to add the border properties to the table.standardtable CSS rule. For the border color, I'm going to use the same color that was applied to the background of the title. So, I'll just copy this value.
Paste that in, the border style should be solid. And the border width should be one pixel. It looks like I have a misspelling here, I'll go ahead and delete that extra D. And now that this CSS is valid, I can save the file, and let's view the results. And now there's a one pixel border surrounding the entire table And that completes my table. The great thing about tables is that they automatically adjust when you change the size of the text.
So, I'll decrease the size of the text, and notice that the table decreases as well. And when I increase the text, the same thing happens. Once the width of the table expands to fit the entire available screen, it'll start to wrap around within the screen and the same thing will happen when I re-size the window. So, this will give you and idea of how this table will be presented when viewed on a smaller screen. Notice that some of the rows on this table are now hidden.
They now appear on the next page. So, the only difficulty with tables, is that some tables contain a lot of information, and they try to fit it all into a small amount of space. Most eBook readers have fairly small screen sizes. Even the iPad, which is one of the larger eBook reading devices available, has problems displaying some tables. Let me show this same table as viewed with the iBooks app on the iPad. So, as you can see, when the iPad is vertically oriented, this table looks great.
but when I flip the iPad horizontally and look at it in a two page spread, the table has to re-flow in order to fit onto the page. And it really doesn't look that great. Notice that the word rank has been divided on to two lines and so has the word headquarters. And part of the text is being cut off at the top of this table, over here on the right facing page. So, to solve this problem I can either use smaller text within the table or I could convert the table to an image instead.
The only drawback to using images instead of actual tables, is that the text within the table will no longer be searchable. Alright so now you know how to format tables in an ePub file. You start by applying paragraph styles and any necessary character styles to the text within the table. Then you apply a Table Style to the table and any necessary Cell Styles to the cells within the table. All of this work sets you up to more easily format the table with CSS Styles, when you edit the ePub file.
Just keep in mind that although table formatting is supported on many eBook readers. It's not supported on all of them. It's definitely supported on the iPad using the iBooks app. And obviously, Adobe Digital Additions supports table formatting, which means that Adobe supported eBook readers such as the Sony Reader do as well.
- Exporting an EPUB file from InDesign CS4 or CS5
- What's inside an EPUB file?
- Editing an EPUB file in Mac OS X or Windows
- Laying out pages
- Working with text
- Exporting graphics
- Creating a table of contents or navigation guide
- Inserting metadata
- Creating scalable images
- Validating an EPUB file