Tabla de contenido horizontal en indesign
Copy link to clipboard
Copied
Saludos cordiales.
Busco replicar una tabla de contenido como la de la imagen adjunta. De manera que los ítems no queden listados de manera vertical como comunmente suelen quedar, sino de manera horizontal. Me refiero a las letras más pequeñas, las cuales están separadas por un guión largo. He tratado de mcuhas maneras y tengo estilos de párrafo para cada ítem, pero no logro que queden listadas de manera horizontal. Agradecería mucho si puedieran ayudarme.
Copy link to clipboard
Copied
After generating and regenerating run a find and replace with a GREP to get the toc in its final form. After setting it up, it is a one command task in the future.
Copy link to clipboard
Copied
You can save your GREP queries - so you won't have to type them every time.
Not sure if anyone noticed - but there is a mix of en and em dashes?
Copy link to clipboard
Copied
in the future, to find the best place to post your message, use the list here, https://community.adobe.com/
p.s. i don't think the adobe website, and forums in particular, are easy to navigate, so don't spend a lot of time searching that forum list. do your best and we'll move the post (like this one has already been moved) if it helps you get responses.
<"moved from using the community">
Copy link to clipboard
Copied
Copy link to clipboard
Copied
… If you prefer Scripting [that will clearly play the Regex defined in my previous post]!
2 versions:
• SCRIPT 1: Only 1 TOC --> no need to place the cursor in the TOC or select something …
• SCRIPT 2: Only 1 TOC --> place the cursor inside the TOC, or Several TOCs --> place the cursor inside the right TOC.
/*
_FRIdNGE-0801_TocUpdate.jsx
Script written by Michel Allio [01/03/25]
See: https://community.adobe.com/t5/indesign-discussions/tabla-de-contenido-horizontal-en-indesign/td-p/15184719
*/
// To Be Defined -------------------------
var myParagraphStyle = "Title_2 - TOC";
var myReplacement = "\\s\\x{2014}~S";
// ---------------------------------------
// SCRIPT 1:
// Supposing there's only 1 TOC:
var myStories = app.activeDocument.stories, S = myStories.length, s;
for ( s = 0; s < S; s++ ) if ( myStories[s].storyType == StoryTypes.TOC_STORY ) {
var myTocStory = myStories[s];
myTocStory.insertionPoints[0].select();
app.menuActions.itemByID(71442).invoke();
break;
}
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\r(?=.)";
app.findGrepPreferences.appliedParagraphStyle = myParagraphStyle;
app.changeGrepPreferences.changeTo = myReplacement;
myTocStory.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = null;
app.selection = null;
/*
// SCRIPT 2:
// Supposing there's 1 TOC. So place the cursor inside the TOC:
// Supposing there's several TOCs. So place the cursor inside the right TOC:
app.menuActions.itemByID(71442).invoke();
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "\\r(?=.)";
app.findGrepPreferences.appliedParagraphStyle = myParagraphStyle;
app.changeGrepPreferences.changeTo = myReplacement;
app.selection[0].parentStory.changeGrep();
app.findGrepPreferences = app.changeGrepPreferences = null;
app.selection = null;
*/
(^/)
Copy link to clipboard
Copied
Very similar approach, I see
You're much better at this than I am.
Maybe adding the control over the last separator so not all \r are replaced? Or does it need it?
Do we need to predefined the myParagraphStyle, wouldn't that mean manual tweaking the script if TOC styles change?
My version I think only requires user selection of the TOC text frame
But it's not supporting multiple TOCs automatically - where I've had multiple TOCs in InDesign before, I don't think it's that common.
I did write a post about this before but can't find it.
But here's an article I found - if it helps the OP somewhat to have multiple TOCs this how to do it.
https://creativepro.com/indesign-tip-multiple-tables-of-contents-in-one-document/
Copy link to clipboard
Copied
As others have mentioned, a relatively simple Find/Change should take care of it. Just make sure you have something you can find that won't be confused with other text. (Paragraph styles looks like it should work here.)
If you need to do multiple Find/Changes, you can use the script provided with InDesign or the (now) free Multi-Find/Change: https://www.automatication.com/product/mfc/
Keep in mind that you will have to run the Find/Change each time you update the TOC. Of course, the TOC only needs to be updated when creating a new proof.
Copy link to clipboard
Copied
I don't think my Regex is so obvious as some try to indicate us (without giving their own proposal)!
if you have in mind a much more simplistic Grep syntax, I take it! 😉
(^/)
Copy link to clipboard
Copied
@FRIdNGE Is your reply to my post? Without seeing the actual structure of the document, I'm not sure anything more complicated than a few simple Find/Changes are required, so I didn't presume.
Copy link to clipboard
Copied
I can get you half way there
But this method automatically inserts a semi-colon and no option to change it - bizarre you can't pick the run-in character...
When generating your TOC in your TOC options - select your H2 or heading 2 that you want and select Run In at the bottom and they will list horizontally
You might be totally happy with the no-option semi colon approach - and doesn't require any additional changes on your part.
=================================================================================
I can kinda get you all the way there - RUN IN OPTION change to dassh
Generate your TOC with the Run In as above
Then run the script
Then when you need to update your TOC run the script and it updates the TOC and removes the ; and adds the dash, you can change the character to anything you need.
But there's a flaw in this that I cannot fix - if your text has a ; in the heading listed horizontally it will probably be removed.
// ReplaceRunInCharacter_UpdateTOC.jsx
// This script updates the TOC (if the TOC text frame is selected)
// then replaces the semicolon followed by a space with your chosen character.
if (app.selection.length === 0 || app.selection[0].constructor.name !== "TextFrame") {
alert("Please select the TOC text frame before running this script.");
} else {
// First, update the TOC using the menu action
try {
var updateAction = app.menuActions.itemByName("Update Table of Contents");
updateAction.invoke();
// Wait a bit for the update to process (adjust delay as needed)
$.sleep(1000);
} catch (e) {
alert("Error updating TOC: " + e);
}
// Now, proceed with the GREP replacement
var tocStory = app.selection[0].parentStory;
// Clear GREP preferences
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
// Set GREP to find the semicolon and a space (the default run-in separator)
app.findGrepPreferences.findWhat = ";\\s";
// Set the replacement to an en dash with spaces (change as desired)
app.changeGrepPreferences.changeTo = " – ";
// Apply the change to the entire TOC story
var changedItems = tocStory.changeGrep();
// Reset GREP preferences
app.findGrepPreferences = app.changeGrepPreferences = NothingEnum.NOTHING;
alert(changedItems.length + " instance(s) replaced.");
}
========================================================================================
I guess the other method mentioned by others is better, DON'T use the RUN IN and replace the \r with a dash
This just means you don't have to do two steps - update the TOC and then run a GREP - it basically does both things, updates the TOC then applies the changes for the look you want.
Run the script to update the TOC and add the dashes.
/*
Replace TOC Paragraph Breaks with Dash (excluding last).jsx
- Updates the TOC.
- Replaces paragraph returns (\r) in "TOC Body Text" with a dash, but leaves the last one untouched.
*/
if (app.selection.length === 0 || app.selection[0].constructor.name !== "TextFrame") {
alert("Please select the TOC text frame before running this script.");
} else {
try {
// Update TOC
var updateAction = app.menuActions.itemByName("Update Table of Contents");
updateAction.invoke();
$.sleep(1000);
} catch (e) {
alert("Error updating TOC: " + e);
}
var tocStory = app.selection[0].parentStory;
// Clear previous GREP settings
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
// **Find all instances of \r inside "TOC Body Text"**
app.findGrepPreferences.appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByName("TOC Body Text");
app.findGrepPreferences.findWhat = "\\r"; // Paragraph return
var foundReturns = tocStory.findGrep();
if (foundReturns.length > 1) {
for (var i = 0; i < foundReturns.length - 1; i++) { // Skip last return
foundReturns[i].contents = " – ";
}
alert((foundReturns.length - 1) + " instances replaced with a dash.");
} else {
alert("No replacements made. Not enough paragraph returns found.");
}
// Reset GREP preferences
app.findGrepPreferences = NothingEnum.NOTHING;
app.changeGrepPreferences = NothingEnum.NOTHING;
}
=======
These methods may need to be tweaked - or maybe there's a cleverer way to do it that I don't know.
I'm just learning scripting so this was a fun task to try something new and maybe learn something myself.
If there's a better script method I'd love to see it.

