Take the 2-minute tour ×
Graphic Design Stack Exchange is a question and answer site for Graphic Design professionals, students, and enthusiasts. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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. )


Edit:

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.

share|improve this answer
    
Excellent animated demonstration!! Only problem is it takes up the width of the line, so it's not really inline. Is there a way to make a table inline like this? –  at. Mar 19 '12 at 19:47
    
@at. Updated my answer. –  Joonas Mar 19 '12 at 22:18
    
Nice work. ++1 for the animations! –  Alan Gilbertson Mar 20 '12 at 0:19
    
I'm trying this now, thanks. Your animations are so helpful! –  at. Mar 20 '12 at 17:16
    
This definitely works, thanks. Not ideal, it seems so strange to me that the top software for writing books and worksheets doesn't have a legitimate highlight or outline mechanism. –  at. Mar 22 '12 at 8:37
add comment

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.

share|improve this answer
    
Agree with you about using a text frame instead of a single-celled table –  at. Mar 22 '12 at 8:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.