10 Jul 2007

For my Bachelorthesis (I write it using Latex), I wanted to have little bordered textboxes that would float next to the main text.

They should explain terms that are mentioned in the main text, so that everyone could read more about that term if (s)he needed to.

It turns out that this is no easy task with Latex. All standard elements I tried would either not float very good, have no border and/or failed to wrap the lines within the info text.

I spent three hours to come up with a nice solution, so it might be useful for people if I share it here.

I defined a new command in the top of the document:

%%%% Custom Command for floating Infoboxes
%%%% usage: \infobox{<title>}{<text>}
\usepackage{picins}                 
\newcommand{\infobox}[2]{
    \parpic(0.34\textwidth,0pt)[lf]{
        \parbox[b]{0.32\textwidth}{
             \bigskip {\bf #1}  \small{{{\sffamily #2}}} \bigskip
        }
    }
    \bigskip
}

The picins package is normally used to place pictures within the text, but when I place a \parbox inside, it works really nice for text.

To create such a infobox somewhere in the document, you just use it like this:

 \infobox{XSLT}{
    XSLT is a stylesheet language that can parse XML files and transform them. The output will be another text file, possibly XML. It offers a lot of capabilities as it is a fully functional programming language.\\
    Like XML, XSLT has also been specified by the W3C consortium.   
  }

Here "XSLT" depicts the bold-faced title within the infobox and the second argument is your info text. Here is a screenshot that shows how a result will look like (I bold-faced "XSLT" in the main text myself):

 

The text block that the infobox floats around is simply the one it precedes in the Latex document. You can also have the infobox on the right. Give the parpic command "rf" instead of "lf" as an option.


The picins command is praised as a really nice package, but it has some problems: If the remainder of the paragraph text is insufficient to fill the area to the side of the infobox, the text from the following paragraph will run through it. It also won't work with enumerate/itemize besides the text. Both of these issues can be fixed on a case-by-case basis, but it can be nasty...

Feel free to drop me a comment if you like it / can do it better / can make it more beautiful.

 

Update (05.08.2007): I made the height of the infobox independent of the text length and used sffamily for the font. I now also mention some problems with picins  that I (and others) ran across.

# lastedited 05 Aug 2007
follow comments per RSS     
  on10 Jul 2007 - 23:28 fromJan
So you decided against sans serif inside the boxes?
[link]
  on11 Jul 2007 - 7:59 fromNic

No. I thought I'd make a really simple version public. Everybody can of course go from here and style it his way.

Also, I haven't done serif yet - how is that done in Latex again?

[link]
  on11 Jul 2007 - 9:38 fromJan
{\sffamily Bla}
[link]
You are seeing a selection of all entries on this page. See all there are.