Highlighting text in Adobe InDesign


I want to have inline code snippets in my InDesign document. Similar to how StackExchange does it, like this. So the gray background is perfect. Basically I just want to highlight certain text. But I can't figure out how to highlight text or have certain text within a text frame have a different background.

I know I can anchor a text frame inline within a text frame. But then I have to size it just right, which is a real pain when I'm constantly changing the text too.

UPDATE: is there really no way to highlight text in InDesign? Seems crazy. By the way, I'm using the latest InDesign CS5.5.

3/19/2012 7:48:00 PM

Accepted Answer

You can make a table from the top menu Table > Insert table into the text frame with settings:

Body rows: 1
Columns 1
Header rows: 0
Footer rows: 0

After that just paste you text inside that table and you can style the table all you want.

and table options can be found from the top menu Table > Table options or Table > Cell options

enter image description here

It's not perfect, but it should do it. I don't know if CS4 or CS5 have better solutions for this.

The not perfect part is that if you make the mistake of resizing the table manually, the minimum height changes into the manually set height. ( Not a big problem though. )


In that case you might want to either use Character styles (or Paragraph styles)

Both can be found from the top menu: Window > Styles >

  1. Make a new Character style, select some text and go to that character styles settings by double clicking it.
  2. Then in the settings either use Underline or strike trough.
  3. Give similar to the following settings: The idea is to make a line that covers the area of the text and then offset it to the right position. ( Underline and Strike through are both set behind the text so this makes a background for the text. ) enter imagedescription here enter image description here

This also isn't perfect because if you change for example the font-size.. you will have to get back to the Underline settings to re-set the underline.

6/30/2014 1:12:00 PM

The Character Style approach that Lollero so beautifully illustrated is the simple way to handle this, using the Underline option, where you have only single-line or partial line snippets.

Where you have a multiple line code snippet, rather than making a table, do this:

  • Drag out a text frame and make its background light grey, then type your text in the appropriate Paragraph Style.

  • Adjust the Text Frame Options so you have the right amount of offset from the edges of the frame.

  • Change the Text Wrap of the frame to "Jump Object" (fourth from the left).

  • With the new text frame selected, create a new Object Style called "Code Snippet," being sure to check the Paragraph Styles checkbox.

  • Drag the text frame with the text cursor to the place where you want to insert the snippet in the text, then anchor it to the end of the preceding paragraph (drag the blue square on the top edge to the end of the paragraph and drop it; you'll see the anchor icon appear on the frame edge) so it will move with the text.