5

To show the difference between my theoretical an practical part, I want to change the background color of the page during practical sections/parts.

Until now I used a new paragraph style, which worked fine: create new paragraph style

Because I can not use Headings or anything like that, I had to use a shaded box. This also worked fine, but I can not insert numbered illustrations and I get the following error:

> ! LaTeX Error: Not in outer par
> mode.
>  \begin{figure}[h]
>                         You've lost some text.  Try typing  <return>  to proceed. If that doesn't work, type  X <return>  to quit.

Does anybody know how to manage to change the background color for individual sections (including headings, images, ...) in LyX?

  • Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – mafp May 30 '13 at 15:00
  • Have you tried \fbox? – Mario S. E. May 30 '13 at 15:32
  • Related: Floating tikzpicture within text in mdframed – Werner May 30 '13 at 15:44
  • You seem to be asking two questions. One regarding the error of placing a float inside mdframed, and the other regarding the change of colour of certain sections... Would you mind clarifying? – Werner May 30 '13 at 15:49
  • The question is only about how to geht a colored background (better would be some graphical y-repeat) over some section (even if there are pagebreaks, pictures, headings). Thank you – drofluga May 30 '13 at 19:04
1

The following MWE reproduces the problem:

\documentclass{article}
\usepackage{mdframed}% http://ctan.org/pkg/mdframed
\begin{document}
\begin{mdframed}
Here is some text.
\begin{figure}
  This is a figure.
\end{figure}
\end{mdframed}
\end{document}

Fundamentally you cannot include a float inside your mdframed environment (which yours is if using the definition from Create new paragraph style in LyX). You have two options for getting around this:

  1. Locate your float outside the mdframed environment and allow it to properly float; or

  2. Add the float package to your document preamble (\usepackage{float}) and use the [H] float specifier. This would allow you to set the "float" inside an mdframed environment.

  • I think I must redefine floats inside mdframed. – Marco Daniel May 30 '13 at 15:53
4

Assumption: The background color is changed only on new pages!

Under "Document Settings > Local Layout" put

Style PageColor
    Category    MainText        
    LatexType   Command
    LatexName   pagecolor
    LabelType   Static
    LabelString "Page Color:"
    LabelSep    xx
    LabelFont
      Color     Red
      Shape     Italic
    EndFont
    Align                 Center
    Preamble
      \usepackage[dvipsnames]{xcolor}
    EndPreamble
End

and "validate". Then after a section title, choose the style "PageColor" and write the name of a color.

lyx document

Notes:

  1. "PageColor" will set the background color for the entire page. If several "PageColor" occur on the same page only the last one has effect. That is the reason of our assumption.

  2. For the colors, all color names of the package "xcolor" are supported. Using the above setting all the colors via the dvipsnames option are supported. You may adjust change the option in above code to get other colors. For more details, see the package documentation of xcolor.

  3. The background color of the entire document can be set in LyX under "Document Settings > Colors". Unfortunately, it is not enough in this case. But it uses the LaTeX command \pagecolor, too.

pdf

  • Good approach! Can i use it also over a specific section (e.g. first page, last paragraph until second page, second paragraph) containing pictures and headings? – drofluga May 30 '13 at 18:57
  • @drofluga Unfortunately, this approach works for entire pages only. Pages cannot be colored partially in this way. – e-birk May 30 '13 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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