tags:

views:

74

answers:

2

This is a screen capture from Pragmatic Bookshelf.

How to make this boxed text with LaTeX? It has it's own heading with underline, and uses color.

And how to make some text with gray background as follows?

Added

Konrad's method works, but it looks like that it doesn't work well with multicolumn package.

Tonio's method shows the gray only for the characters, but I want to have the gray box expanded to the end of \textwidth.

I posted another question with respect to the \texwidth, and it seems to working anyway.

+2  A: 

You should use the color package.

For example,

\colorbox{red}{Black text on red background}

creates a black text, with a red background. A good description of the color capabilities can be seen here, and an extended example here.

tonio
And the rounded box can be obtained using a technique similar to the one used [here](http://www.cv-templates.info/2009/07/wrapping-text-in-rounded-corners-colorbox-in-latex-with-tikz-and-pgf/), with [tikz/pgf](http://www.texample.net/tikz/).
tonio
@tonio : Is there a way to make \colorbox expand to the end of \textwidth?
prosseek
You can simply put your text in a `parbox` of length `\textwidth`, with `\colorbox{red}{\parbox{\textwidth}{Black text on red background}}`
tonio
+2  A: 

The rounded box is most easily created using TikZ:

\begin{tikzpicture}
  \draw node[draw=black,fill=black!20,rounded corners,inner sep=2ex,text width=\textwidth] {
    Lorem ipsum dolor sit amet \dots
    };
\end{tikzpicture}
Konrad Rudolph
@Konrad : width=\textwidth doesn't seem to work with multicolumn environment.
prosseek
@prosseek: there seem to be several quirks with boxes of fixed width … I’m no expert of TikZ myself, and I have a lot of trouble getting some of the things to work … but try `0.5\textwidth`.
Konrad Rudolph
@prosseek: the following worked for me: use [`\newlength`](http://www.eeng.dcu.ie/local-docs/latex-help/ltx-87.html) to define a new length (let’s call it `\halflength`), set that length to `0.5\textwidth`, add to that `-0.5\columnsep` (using `\setlength` and `\addtolength`, respectively) and use the resulting `\halflength` as the text width.
Konrad Rudolph
It simply amazes me that this answer has got a downvote. Come on people … seriously?
Konrad Rudolph