Take the 2-minute tour ×
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.

I'm not sure of the name of what I need. I would like to set some text in a box or sidebar, as I've seen in some textbooks. The main text will refer the reader to the sidebar for more details. I would like this shaded. There is too much text for marginpar. I could just use a float figure? I'd prefer it to be half the width of the page though. Is there an easy way to achieve this? I'm not sure what search terms to use to find out about this.

share|improve this question
1  
Google for tufte-latex. Example of layout: dl.getdropbox.com/u/502901/naurtf.pdf –  JLDiaz Feb 25 '13 at 8:32
    
Thanks. The layout I wanted integrates the sidebar with the text though, rather than placing it in a wide empty margin. The body text would have to be a single column next to the box. –  SabreWolfy Feb 25 '13 at 8:56
3  
Oh, I understand, you want some kind of wrapfigure? You can use this environment to put text inside also (and omit the caption). However these kind of environments are know to produce lot of problems in conjunction with itemizes, changes of section, etc. –  JLDiaz Feb 25 '13 at 9:07

1 Answer 1

You can do this, with certain restrictions, using the wrapfig package together with mdframed or tcolorbox. Here's a little example using tcolorbox:

\documentclass{article}
\usepackage{wrapfig}
\usepackage{tcolorbox}
\usepackage{lipsum}

\newenvironment{WrapText}[1][r]
  {\wrapfigure{#1}{0.5\textwidth}\tcolorbox}
  {\endtcolorbox\endwrapfigure}

\newcommand\Text{% some text for the example
tesque cursus luctus mauris. Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum.}

\begin{document}

\begin{WrapText}
\Text
\end{WrapText}
\lipsum[2]
\lipsum[2]
\begin{WrapText}
\Text
\end{WrapText}
\lipsum[1-3]

\end{document}

enter image description here

And a solution with mdframed:

\documentclass{report}
\usepackage{graphicx}
\usepackage{wrapfig}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{lipsum}

\newenvironment{WrapText}[1][r]
  {\wrapfigure{#1}{0.5\textwidth}\mdframed[backgroundcolor=gray!20,skipabove=0pt,skipbelow=0pt]}
  {\endmdframed\endwrapfigure}

\newcommand\Text{% some text for the example
tesque cursus luctus mauris. Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum.}

\begin{document}

\begin{WrapText}
\Text
\end{WrapText}
\lipsum[2]
\lipsum[2]
\begin{WrapText}
\Text
\end{WrapText}
\lipsum[1-3]

\end{document}

enter image description here

Since both mdframed and tcolorbox are highly customizable, you can obtain pretty easily the desired layout for the colored box.

And now, the bad news. Since wrapfig is being used, some restrictions will have to be observed; in particular, the package documentation mentions these:

• The environment should be placed so as to not run over a page break.

• The environment must not be placed in special places like lists.

• For esthetic reasons, only plain text should wrap around the figure. Section titles and big equations look bad; lists are bad if the figure is on the left. (All these function properly, they just don’t look very good.) Small equations look fine.

• It is convenient to begin the environment between paragraphs, but if you want placement in the middle of a paragraph, you must put the environment between two words where there is a natural line break.

share|improve this answer

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.