LibreOffice Writer - How to format text as code?

6,935

Solution 1

See the following images to know how to create a text-box.

Click the icon with an A with a vertical bar next to it: enter image description here

Type whatever code you want to put in the box and then right-click on the border on the box. Select Line from the menu. enter image description here

Select the style you want for the box's border and click ok.

enter image description here

Solution 2

IMO it's better to use "Insert > Frame > Frame..." -- do not use a text box.

Several reasons:

  • Text in frames can use paragraph styles. Text that you enter into a text box may be formatted only by hand. If it's a large document, you will want to create a paragraph style for code, and use the paragraph style instead of direct formatting. Suppose you need to change the code font later. If you used styles, you can change the style and all code examples update. If you used text boxes and direct formatting, you will have to edit every text box by hand. Not recommended.

  • AFAICS normal paragraph text automatically avoids frames, whereas, when I tried text boxes, I had to set text wrapping manually.

The point about styles is important. Styles are underused, but IMO if you're working on anything longer than, oh, 4 or 5 pages, the time you spend setting up styles will pay off many times over. Avoid LO features (like text boxes) that don't support styles.

Share:
6,935

Related videos on Youtube

Mazdak
Author by

Mazdak

Updated on September 18, 2022

Comments

  • Mazdak
    Mazdak almost 2 years

    Is is possible to put code snippets into an OpenDocument Text file (.odt) file? I want it to be inside a bordered box, etc...

    And I would like to know whether there is any way to add plugins to LibreOffice Writer?

    • TheWanderer
      TheWanderer about 9 years
      You mean as plain text, within a bordered box or as an actual, functioning code?
    • TheWanderer
      TheWanderer about 9 years
      Have you tried a text box with a formatted border?
    • Mazdak
      Mazdak about 9 years
      @Zacharee1 No i didn't! i don't know what is that :)
    • TheWanderer
      TheWanderer about 9 years
      Check the Insert menu for a text box. You can then format it. I can't tell you exactly what/where it is since I don't have my computer.
    • Mazdak
      Mazdak about 9 years
      @Zacharee1 Sorry but there is no text box in my inser menu
    • TheWanderer
      TheWanderer about 9 years
      I'll look when I have the chance. If there's an Object menu under Insert, look there.
  • Mazdak
    Mazdak about 9 years
    Thanks but this couldn't help me!
  • terdon
    terdon about 9 years
    @Kasra when an answer didn't help you, you need to explain why. Otherwise, we can't understand what's missing. How was this not enough for you? What else do you need?