12

I'm using framed to create a little callout box for tips and other information in a book. So for it's going well however I cannot get the icon (using ding) to sit in the margin.

It currently looks like this:

http://dl.dropbox.com/u/11125156/latex_sample1.png

whereas I'd like it to look like this mock up

enter image description here

I'm using the following code

\documentclass[a4paper,12pt]{article}
\usepackage{verbatim}
\usepackage{color}
\usepackage[english]{babel}
\usepackage{pifont}
\usepackage[strict]{changepage}
\usepackage{framed}
\usepackage{blindtext}

\definecolor{formalshade}{rgb}{0.95,0.95,1}

\newenvironment{tipbox}{%
  \def\FrameCommand{%
  {\Huge\ding{43} }
    \hspace{1pt}%
    {\color{green}\vrule width 2pt}%
    {\color{formalshade}\vrule width 4pt}%
    \colorbox{formalshade}%
  }%
  \MakeFramed{\advance\hsize-\width\FrameRestore}%
  \noindent\hspace{-4.55pt}% disable indenting first paragraph
  \begin{adjustwidth}{}{7pt}%
  \vspace{2pt}\vspace{2pt}%
}
{%
  \vspace{2pt}\end{adjustwidth}\endMakeFramed%
}

\begin{document}

\blindtext

\begin{tipbox}
You can expect your organisation to perform better, but only if everyone pointing in the same direction.
\end{tipbox}

\blindtext

\end{document}

If putting it in the margin is too difficult, just moving the icon to the top of the box would be great :-)

  • Welcome to TeX.sx! Please make sure that all images are uploaded using the official stackexchange interface, i.e. the image icon on top of the text field (shortcut: CTRL+G). This ensures that all images are always accessible and do not expire. As new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. – Martin Scharrer Jun 6 '12 at 10:19
  • Thanks for the feedback. I'll ensure I do that next time :-) – eleybourn Jun 6 '12 at 10:32
9

Here's a solution with mdframed

\documentclass{article}

\usepackage{mdframed}
\usepackage{pifont}
\usepackage{xcolor}
\definecolor{formalshade}{rgb}{0.95,0.95,1}

\usepackage{lipsum}

\newmdenv[
  skipabove=\topskip,
  skipbelow=\topskip,
  innermargin=0pt,
  outermargin=0pt,
  innerleftmargin=4pt,
  innerrightmargin=4pt,
  innertopmargin=2pt,
  innerbottommargin=2pt,
  backgroundcolor=formalshade,
  topline=false,
  rightline=false,
  bottomline=false,
  linecolor=green,
  linewidth=2pt,
   ]{tipbox*}
\newenvironment{tipbox}[1][43]
  {\begin{tipbox*}
   \makebox[0pt][r]{\smash{\raisebox{-.333\height}{\Large\ding{#1}\hspace{10pt}}}}\ignorespaces}
  {\end{tipbox*}}

\begin{document}
\lipsum[1]

\begin{tipbox}
You can expect your organisation to perform better, but only if everyone is pointing in the same direction.

You can expect your organisation to perform better, but only if everyone is pointing in the same direction.
\end{tipbox}

\lipsum[2]
\end{document}

enter image description here

You can get a black hand with

\begin{tipbox}[42]

or use the number of any symbol you want.

| improve this answer | |
  • Great stuff. I had to fight to get mdframed working on Ubuntu, but it does exactly what I need. – eleybourn Jun 8 '12 at 3:26
6

The \llap command is your friend. It typesets the content passed as parameter "to the left" without changing the insert position.

\documentclass[a4paper,12pt]{article}
\usepackage{verbatim}
\usepackage{color}
\usepackage[english]{babel}
\usepackage{pifont}
\usepackage[strict]{changepage}
\usepackage{framed}
\usepackage{blindtext}

\definecolor{formalshade}{rgb}{0.95,0.95,1}

\newenvironment{tipbox}{%
  \def\FrameCommand{%
  {\llap{\Huge\ding{43}\hspace{1pt}}}
    %
    {\color{green}\vrule width 2pt}%
    {\color{formalshade}\vrule width 4pt}%
    \colorbox{formalshade}%
  }%
  \MakeFramed{\advance\hsize-\width\FrameRestore}%
  \noindent\hspace{-4.55pt}% disable indenting first paragraph
  \begin{adjustwidth}{}{7pt}%
  \vspace{2pt}\vspace{2pt}%
}
{%
  \vspace{2pt}\end{adjustwidth}\endMakeFramed%
}

\begin{document}

\blindtext

\begin{tipbox}
You can expect your organisation to perform better, but only if everyone pointing in the same direction.
\end{tipbox}

\blindtext

\end{document}

enter image description here

| improve this answer | |
  • 1
    \llap is correct but you should start the environment with this command to get the dingbat at the top of the environment. – Marco Daniel Jun 6 '12 at 11:46
5

Solving a very similar problem I used the marginnote package. So (using the book class) it is possible to decide what is shown on the left and/or right page: \marginnote[left]{right}. Using the \scalebox command from the graphicx package one can mirror the symbol, so that an approach could be:

\documentclass[a4paper,12pt]{book}
\usepackage{verbatim}
\usepackage{color}
\usepackage[english]{babel}
\usepackage{pifont}
\usepackage[strict]{changepage}
\usepackage{framed}
\usepackage{blindtext}
\usepackage{marginnote}
\usepackage{graphicx}

\definecolor{formalshade}{rgb}{0.95,0.95,1}

\newenvironment{tipbox}{%
\def\FrameCommand{%
    \hspace{1pt}%
    {\color{green}\vrule width 2pt}%
    {\color{formalshade}\vrule width 4pt}%
    \colorbox{formalshade}%
  }%
  \MakeFramed{% 
  %
   \marginnote[\Huge\ding{43}]{\scalebox{-1}[1]{\Huge\ding{43}}}%
   %
   \advance\hsize-\width\FrameRestore}%
   \noindent\hspace{-4.55pt}% disable indenting first paragraph
   \begin{adjustwidth}{}{7pt}%
   \vspace{2pt}\vspace{2pt}%
}
{%
  \vspace{2pt}\end{adjustwidth}\endMakeFramed%
}

\begin{document}

\blindtext

\begin{tipbox}
You can expect your organisation to perform better, but only if everyone pointing in the same direction.
\end{tipbox}

\blindtext
\newpage
\begin{tipbox}
You can expect your organisation to perform better, but only if everyone pointing in the same direction.
\end{tipbox}
\end{document}

enter image description here

| improve this answer | |
  • I really like this approach (though for me I need it to be always on the left, so I'm using the above mdframed version). – eleybourn Jun 8 '12 at 3:27

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.