Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to make a tabular TOC (Table of Contents) automatically in Adobe Indesign

Enthusiast ,
Dec 23, 2024 Dec 23, 2024

How do I make a TOC automatically like the one attached in the screenshot ?

Thanks

TOPICS
How to , Scripting
2.0K
Translate
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

correct answers 1 Correct answer

LEGEND , Dec 25, 2024 Dec 25, 2024

@Bedazzled532 

 

Not saying that I'm (very) good in JavaScript'ing 😉 but "yes, I can" 😉

 

app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = "^p";
app.changeTextPreferences.changeTo = "^t";
app.findTextPreferences.appliedParagraphStyle  = "TOC Chapter";
app.selection[0].parentStory.changeText();
app.selection[0].parentStory.paragraphs.itemByRange(app.selection[0].parentStory.paragraphs[1],app.selection[0].parentSto
...
Translate
Community Expert ,
Dec 23, 2024 Dec 23, 2024
  1. Make a toc based on paragraph styles.
  2. Convert the toc into a a table. 

To make it faster, save the table style to reapply it after changes. You have to generate it again and apply these steps after any change. 

Translate
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
Enthusiast ,
Dec 23, 2024 Dec 23, 2024

@Willi Adelberger Thanks for the reply. If you notice the TOC  entry has following format:

SlNo.      Chapter Name     Chapter Author      Page Number.

Serial number will not be a problem. I have made Numbering para style for TOC entry. How do I include "Chapter Author" in the same line ? Currently I have given a separate style to Chapter Author and changed its leading to 0.

Translate
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
Enthusiast ,
Dec 23, 2024 Dec 23, 2024

@Willi Adelberger I have reached 98% close to the example. I just need a vertical line next to the serial number. This will make this TOC 98% automatic. No need to convert it to table.

 

After generating the toc, will have to run grep shown in the screenshot.

 

I have shared the toc idml and current screenshot.

Translate
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
LEGEND ,
Dec 24, 2024 Dec 24, 2024

Creative 😉

 

But I think you can make it much simpler:

 

"Standard" TOC - as mentioned by @Willi Adelberger:

RobertatIDTasker_1-1735049121887.png

 

 

RobertatIDTasker_0-1735049092769.png

 

Now, replace "end of paragraph" with a TAB - in only TOC Chapter ParaStyle:

RobertatIDTasker_2-1735049164975.png

 

Convert Numbering to Text:
RobertatIDTasker_3-1735049205789.png

 

RobertatIDTasker_4-1735049215507.png

 

Convert to Table:

RobertatIDTasker_5-1735049232569.png

 

RobertatIDTasker_6-1735049243545.png

 

 

Translate
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
Enthusiast ,
Dec 24, 2024 Dec 24, 2024

@Robert at ID-Tasker Thanks for the steps. I will try this method also and update. 

Translate
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
Enthusiast ,
Dec 25, 2024 Dec 25, 2024

@Robert at ID-Tasker I tried you method. Its great but the only problem would be when I make any update on the TOC. I will have to do the steps again.  Any suggestions using post toc steps using script ? Thanks

Translate
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
LEGEND ,
Dec 25, 2024 Dec 25, 2024

@Bedazzled532

 

Yes, it shouldn't be a big deal for someone good in JS to convert those steps into a working script.

 

Translate
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
LEGEND ,
Dec 25, 2024 Dec 25, 2024

@Bedazzled532 

 

Not saying that I'm (very) good in JavaScript'ing 😉 but "yes, I can" 😉

 

app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = "^p";
app.changeTextPreferences.changeTo = "^t";
app.findTextPreferences.appliedParagraphStyle  = "TOC Chapter";
app.selection[0].parentStory.changeText();
app.selection[0].parentStory.paragraphs.itemByRange(app.selection[0].parentStory.paragraphs[1],app.selection[0].parentStory.paragraphs[-1]).convertBulletsAndNumberingToText();
app.selection[0].parentStory.paragraphs.itemByRange(app.selection[0].parentStory.paragraphs[1],app.selection[0].parentStory.paragraphs[-1]).convertToTable();

 

After you refresh your TOC - you need to select its TextFrame and run the above script. It works on the ParentStory - so you don't have to reflow it in case there is an overset.

There is no error checking - code would be few times longer - but there aren't many trip hazards.

 

Attached is your INDD file with my modifications - so you can check TOC setting and get ParaStyles.

 

 

 

And here is a sample Task for my ID-Tasker - pretty much the same steps as you would've to do manually and what script above is doing - but you don't have to be a coder:

 

RobertatIDTasker_0-1735139978235.png

 

Translate
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
Enthusiast ,
Dec 25, 2024 Dec 25, 2024

@Robert at ID-Tasker Excellent work Robert. Thank you so much. It really helped a lot. I would also like to thanks @Willi Adelberger for his effort.

Translate
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
LEGEND ,
Dec 25, 2024 Dec 25, 2024

@Bedazzled532

 

You're welcome. 

 

Translate
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
Community Expert ,
Dec 25, 2024 Dec 25, 2024

I would take a simplier approach, being simple minded myself...

Just build a regular TOC with paragraph rules and put the verticle rules manually behind it. The verticle rules might have to be adjusted for height, but that wouldn't be hard based on the example. 

 

David Creamer: Community Expert (ACI and ACE 1995-2023)
Translate
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
LEGEND ,
Dec 25, 2024 Dec 25, 2024
quote

I would take a simplier approach, being simple minded myself...

Just build a regular TOC with paragraph rules and put the verticle rules manually behind it. The verticle rules might have to be adjusted for height, but that wouldn't be hard based on the example. 

 

By @Dave Creamer of IDEAS

 

Yes, but in this case - TOC is build from two Paragraphs - so some post-processing is needed anyway.

 

Even if you mean to use the formatting already created by OP - and just add vertical lines to simulate table look - then their height would have to be adjusted every time number of entries change or their length.

 

Translate
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
Community Expert ,
Dec 26, 2024 Dec 26, 2024
quote

- then their height would have to be adjusted every time number of entries change or their length.


By @Robert at ID-Tasker

I think that is what I said. 😁

David Creamer: Community Expert (ACI and ACE 1995-2023)
Translate
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
LEGEND ,
Dec 26, 2024 Dec 26, 2024

@Dave Creamer of IDEAS

 

Then scripting solution is rather more convenient? Unless I'm missing something?

 

Translate
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
Enthusiast ,
Dec 26, 2024 Dec 26, 2024
LATEST

@Dave Creamer of IDEAS After creating the TOC, its better to run the script. I have modified the script a little bit to suit my needs (still under process).

 

Here is the updated script, just in case if it helps anyone:

function main(){
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
app.findTextPreferences.findWhat = "^p";
app.changeTextPreferences.changeTo = "^t";
app.findTextPreferences.appliedParagraphStyle  = "TOC Heading";
app.selection[0].parentStory.changeText();
app.selection[0].parentStory.paragraphs.itemByRange(app.selection[0].parentStory.paragraphs[1],app.selection[0].parentStory.paragraphs[-1]).convertBulletsAndNumberingToText();
var myTable = app.selection[0].parentStory.paragraphs.itemByRange(app.selection[0].parentStory.paragraphs[1],app.selection[0].parentStory.paragraphs[-1]).convertToTable();

//assign a table style to the table
//myTable[0].appliedTableStyle = "mytab"; 

//assign same width to all columns
//myTable[0].columns.everyItem().width = "25 mm";

//First column and fourth columns width set to 10mm
myTable[0].columns[0].width="10 mm";
myTable[0].columns[3].width="10 mm";

//get the width of the textframe and deduct 10 + 10 i.e 20mm
//and divide the remaining width to column 2 and 3
var fw = getFrameWidth();
myTable[0].columns[1].width=(fw-20)/2;
myTable[0].columns[2].width=(fw-20)/2;
//alert(fw);
}

function getFrameWidth(){
var tf;
var sel = app.selection[0];

if(sel.hasOwnProperty('baseline')) {
  tf = sel.parentTextFrames[0];
} else if (sel instanceof TextFrame) {
  tf = sel;
}

var tfWidth = tf.geometricBounds[3] - tf.geometricBounds[1];
return tfWidth;
}
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined,UndoModes.ENTIRE_SCRIPT,'main');
Translate
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