TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am referring to the coderule environment (see Override \centering to left justify an image) presented earlier by @TH as answer to the following question: Override \centering to left justify an image

I use the defined coderule environment for equations (i.e., flalign, amsmath package). Since my equations are quite long, I allow automatic page breaking for them (\allowdisplaybreaks[1]). If I apply the coderule around the flalign, the equations do not break anymore and leave a lot of unused white space. Is it possible to change the coderule environment in such a way that it adapts to the automatic page break?

share|improve this question
Welcome to TeX.sx! Please add a minimal working example (MWE) that compiles and shows the working of your coderule environment. It would make it much easier for others to investigate modifications rather than re-inventing the wheel or gather information from different sources across TeX.SX. – Werner Nov 1 '11 at 15:41

Here is a completely revamped version of the coderule environment. This time using the mdframed environment from the similarly-named mdframed package. The package is loaded with the framemethod=tikz, thinking that you're compiling your document using pdflatex.

Although mdframed produces a framed environment, we set the top, bottom and right margins and lines to 0pt, and adjust only the left margin specifications. mdframed naturally breaks across a page without problem, thereby providing the required functionality by default.

In the following minimal example, the coderule environment takes 3 optional arguments:

\begin{coderule}[<rule width>][<rule sep>][<rule colour>]

The width of the rule is set by the first optional argument <rule width> (default is 1em), while the separation between the rule and the paragraph text is set by the second <rule sep> (default is 1em). Finally, the third optional argument allows you to modify the colour to suit your needs (default is black).

enter image description here

\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{amsmath}% http://ctan.org/pkg/amsmath
\usepackage[framemethod=tikz]{mdframed}% http://ctan.org/pkg/mdframed
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentEnvironment{coderule}{O{1em} O{1em} O{black}}%
  {% \begin{coderule}[<rule width>][<rule sep>][<rule colour>]
  {\end{mdframed}}% \end{coderule}

\lipsum[1] \bigskip \bigskip \bigskip
    f(x) &= ax^2+bx+c \\
    f(x) &= ax^2+bx+c \\
    f(x) &= ax^2+bx+c \\
    f(x) &= ax^2+bx+c
  Here is a short introduction:
    f(x) &= ax^2+bx+c \\
    f(x) &= ax^2+bx+c \\
    f(x) &= ax^2+bx+c \\
    f(x) &= ax^2+bx+c \\
    f(x) &= ax^2+bx+c \\
    f(x) &= ax^2+bx+c

Of course, the choice of 3 additional arguments may be superfluous. So, that can be removed as well, or the order switched around. Also, the choice of align from amsmath is interchangeable with flalign.

xparse provided the environment definition interface, while lipsum was used for dummy text generation, Lorem Ipsum style.

share|improve this answer

Your Answer


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.