5

EDIT: I should have given a MWE based on memoir (which I am using) where the inner and outer margins are initially different. I would like the margins to be the same in that new environment. (Inner margin is the left margin on odd number pages and the right margin on even number pages ... or the other way around.)


I would like to be able to define an environment that

  1. changes the width of the text;
  2. changes the number of columns;
  3. adds a background color;
  4. works across page boundaries.

So far, the best I can get is three out of four; items 2 and 3 seem to be non-compatible choices.

Here's a MWE which shows the intent. (Unfortunately, like the documentation states, adjusmulticols and mdframed are not compatible.)

\documentclass{article}
\usepackage{adjmulticol}

\usepackage{mdframed}
\usepackage{lipsum}

\begin{document}
\lipsum[1]
%\begin{mdframed}[background=yellow]
\begin{adjmulticols}{2}{-1in}{-1in}
\lipsum
\end{adjmulticols}
%\end{mdframed}

\begin{mdframed}[backgroundcolor=yellow,leftmargin=-1,rightmargin=-1]
%\begin{adjmulticols}
\lipsum
%\end{adjmulticols}
\end{mdframed}
\end{document}
7

enter image description here

the standard multicol can cope with the page margins being locally changed, so you just need to drop in a coloured rule at the point it is assembling the columns, something like this:

\documentclass{article}
\usepackage{multicol}

\usepackage{color}

\makeatletter

\newenvironment{wider}
               {\list{}{\leftmargin-1cm\relax\rightmargin\leftmargin}%
                \item\relax}
               {\endlist}

\def\foo#1\full@width#2#3\foo{%
\def\page@sofar{%
#1%
\full@width{%
     {\color{yellow}\vrule \@width \full@width}%
     \kern-\full@width
#2}%
#3}}
\expandafter\foo\page@sofar\foo



\usepackage{lipsum}


\begin{document}\color{black}
\lipsum[1]

\begin{wider}
\begin{multicols}{2}
\lipsum
\end{multicols}
\end{wider}


\begin{multicols}{3}
\lipsum
\end{multicols}

\end{document}

UPDATE

Or a minor variation, as requested in the comments, just using memoir in the example, and just making the environment wider on one side, and shifting the rule depending on the page

\documentclass{memoir}
\usepackage{multicol}

\usepackage{color}

\makeatletter

\newenvironment{wider}
               {\list{}{\leftmargin0pt\relax
                        \rightmargin-2cm\relax}%
                \item\relax}
               {\endlist}

\def\foo#1\moveright#2\full@width#3#4\foo{%
\def\page@sofar{%
#1%
\dimen@\multicol@leftmargin
\ifodd\c@page\else\advance\dimen@-2cm\relax\fi
\moveright\dimen@
\hbox to \full@width{%
     {\color{yellow}\vrule \@width \full@width}%
     \kern-\full@width
#3}%
#4}}
\expandafter\foo\page@sofar\foo

.... rest as before

6
  • Since I plan to use memoir instead of article (I should have done that in my MWE), how do I modify this to have the same left and right margins regardless if the page is even or odd. I tried to look up \list in my (arguably very old) copies of the TeXbook and the LaTeX user guide but did not find it. Google is not helping either...
    – André
    Apr 4 '12 at 17:23
  • You absolutely need to use adjmulticols for that, but the relevant code by David is in the \page@sofar hack, so this should hopefully also work with adjmulticols. Apr 4 '12 at 17:27
  • I;m not sure I understand the comment about margins, in that wider environment (which is just the code for the standard latex quote env but with negative rather than positive offset) I just took a cm off each margin, so whatever relationship between the margins and odd and even pages held before should still hold, apart from being reduced? Apr 4 '12 at 18:39
  • With memoir and the twoside option, I have a larger outer margin than inner one (say by 2in), basically to leave room for notes in the margin. With [adjmargincol] I can do \begin{adjmulticols}{3}{0in}{-2in} and the multicolumn text will now take the full width of the page, either intruding on the left or right margin depending if the page is odd or even (or the other way?), and effectively have both margins the same size.
    – André
    Apr 4 '12 at 18:56
  • 1
    added memoir example to my answer Apr 4 '12 at 19:28
5

A good package to have a look is the tcolorbox, although sadly also does not break across pages.

enter image description here

\documentclass{article}
\usepackage{multicol,lipsum}
\usepackage{tcolorbox}
\begin{document}
\begin{tcolorbox}[width=15cm]
\begin{multicols}{3}
\lipsum[1-3]
\end{multicols}
\end{tcolorbox}
\end{document}
5
  • I may be forced to use this (plus manual editing...) but I really would like to have it break across pages.
    – André
    Apr 4 '12 at 17:03
  • @André Personally I dislike boxes breaking across pages. Normally you box something to make it stand-out, so you do not want to split it. Apr 4 '12 at 17:13
  • 1
    I would normally agree... What I want to use this for is to shade out worked-out examples in physics and math notes, reproducing the look often found in introductory textbooks. The shading here is to de-emphasize the examples, enabling the student to quickly jump over if they so desire.
    – André
    Apr 4 '12 at 17:26
  • @André Have a look at Steward's Calculus to see a better scheme. Apr 4 '12 at 17:51
  • @YiannisLazarides: Since version 2.00 tcolorbox introduced breakable boxes across pages.
    – Ignasi
    Jul 2 '13 at 8:01
0

Apparently, another solution is boites with some pstrick magic as demonstrated here. Unfortunately, I have not been able to reproduce it as I get a Non-PDF special ignored! error message (using pdflatex).

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.