July 6 2006 • 8:30 PM

Merging Two Tables Together in InDesign

Sharon wrote: Is there any way to merge two tables into a single table?

The bad news is that there is no way to merge two tables together in InDesign. The good news is that you can do it outside of InDesign! The trick? Tagged text. [Editor's note written ex post facto: This is a great way to learn about tagged text, but be sure to read reader's comments below for a better solution.]

Tagged text is an often-overlooked feature in InDesign, but it lets you do all kinds of cool things to text. You can think of tagged text as being like HTML: It’s a way to describe text formatting using codes. The best way to see what tagged text looks like is to select some text in InDesign, choose File > Export, pick InDesign Tagged Text from the Save as Type (or Format) popup menu, and save it to disk. Now open that file in a text editor, such as NotePad, TextEditor, or TextWrangler.

Virtually anything you can put in a text frame you can express with tagged text. (I say “virtually” because I haven’t tested everything and I bet there are some things — such as anchored objects? — that just won’t handle the conversion to tagged text well.) Tables are part of a text flow, and they are converted into tagged text well. So if you put two tables in a row and export them as tagged text, you can tweak the codes to merge them into a single table.

Is this for the faint of heart? No! But it’s fun to know you can do it.

First, search for the text “TableStart:”. For example, it may appear like this: “TableStart:2,4:0:0″. That means this table has two rows and four columns. Change the number of rows to the total (this table plus the second table).

Now search for “TableEnd:”. That signifies the… well, I think you can get that one. To merge the table, delete all the text from the TableEnd tag (including the angle brackets around it) and ending just before the next “RowStart” tag. (But leave the angle bracket before “RowStart”, of course!)

Finally, save your new document (I suggest saving it with a new name so you can go back to the original if you make a mistake) and import this text file into your InDesign document using File > Place. The tables should be merged! If it doesn’t work, try again. If it still doesn’t work, take a look at the sample files I put here. If it still doesn’t work after you try 3 times and you can’t figure out what you’re doing wrong, you can email me. ;) I don’t guarantee this trick; it’s clearly playing with fire, but you can cook up some great results!

7 Responses discussing this post. Add yours below.

  1. July 6th, 2006 • 9:21 pm • Link

    Yes, great trick

    But what about this, if the tables have the same number of columns, well if tables are simple ?

    Table 1 has 4 lines and 4 columns
    [Separated]
    Table 2 has 10 lines and 4 columns, some of the cells are even merged

    - Select the whole Table 2 by clicking in the upper left corner
    - Edit > Cut
    - Click in a cell in the last line of the table
    - Right-Clic > Insert > Row… Add 10 lines Down
    - Select these 10 lines and…
    - Edit > Paste and that’s it, even merged cells are preserved…

  2. July 6th, 2006 • 9:24 pm • Link

    That’s a great “tinkering under the hood” solution — I love that sort of thing. And any excuse to play around with and familiarize yourself with the power of InDesign Tagged Text is worth exploring.

    But there may also be a way to “merge” two tables more simply, provided the tables themselves are fairly simple. I use quotes because it’s not really a true merge function, but it will put all the data into one table.

    Let’s say you have a table of three rows and four columns (the source table) that you want to include in a table with any number of rows, but also with four columns (the destination table). First, add three rows to the destination table, then select the three rows from the source table by either dragging through all the cells in all three rows or selecting all three rows when you get the InDesign arrow cursor that selects whole rows or columns. Cut or copy those rows, then select the three empty rows you created in the destination table and paste in the rows from the source table.

    Again…this is a simple method for simple tables. And it will work with columns, too…but first you need to create (insert) the “placeholder” rows/columns you need so that what you copy from the source table has somewhere to go in the destination table. Many things could trip you up on this — such as the presence of merged cells in either the source or destination table — but if your two tables aren’t too complex, it does work.

    You can also paste an entire table into one cell of another table if, for example, you wanted to avoid creating a complex series of merged cells in an otherwise simple table. But the individual cells of that “nested” table then have to be selected, edited and formatted independently of table into which it’s been pasted.

  3. July 6th, 2006 • 9:26 pm • Link

    I need to learn to write less and click “Submit Comment” faster. Branislav beat me to it. :)

  4. David Blatner
    July 6th, 2006 • 10:41 pm • Link

    I tip my hat to Branislav and Michael. I was so proud of my complicated solution that I forgot even to try the simple solution! As Branislav noted, copying and pasting rows (or columns) works even for merged cells.

    It appears to work for split cells, too, but note that a horizontally split cell adds an additional row. That is, if you split a cell horizontally, then try to select that one row, you actually have to select two rows! I hadn’t noticed that before.

    So chalk this table-merging exercise up to a good excuse to discuss (and play with) tagged text. Oh well.

    Next week: How to type characters into InDesign by toggling binary code in with dip switches. ;)

  5. September 28th, 2006 • 1:13 pm • Link

    The copy paste is the obvious solution, but seems to trip up when things like embedded tables are inside the cells to be pasted.
    And pasting cells doesn’t seem to keep all the attributes - it’s a little hit and miss.
    So the tagged text was a good experiment for me, even if recreating and reformatting the cells might have been quicker in the end :)

  6. Liam
    August 14th, 2007 • 4:32 am • Link

    Thank you. Now that I’m up to CS3, I know I should have known this trick by now, but reading this has been a great help!

  7. ej
    February 1st, 2008 • 5:29 pm • Link

    What about a simpler solution for merging hundreds of tables? I’m using Data Merge to create a table of items from an excel sheet (with some complicated formatting) and I can create a table of one row for each record, but merging those tables has proved… troubling.

Subscribe to the Discussion

Get the ongoing discussion surrounding "Merging Two Tables Together in InDesign" delivered to you. Click here to subscribe via RSS.

Leave a Reply

You can use limited HTML tags, such as <em></em> for emphasis/italics and <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

InDesignSecrets reserves the right to edit and/or remove posts and comments.