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 would like to obtain something like in the following picture (I've put Z! instead of the danger symbol).

Formatting

In the following code, I would like to put the danger symbol on the vertical rule.

I think that can be done by putting one kind of box on the start of the vertical rule, the box would have a white background and would contain the symbol.

If the symbol can be add at every new page where the verical rule is broken, it would be great.

\documentclass[a4paper,10pt]{article}
    \usepackage[utf8]{inputenc}
    \usepackage[x11names, svgnames]{xcolor}
    \usepackage{mdframed}
    \usepackage{graphicx}
    \usepackage{fourier-orns}

    \definecolor{warningColor}{named}{Red3}
    \newcommand{\warningSymbol}{\raisebox{\depth}{\danger}}

    \newenvironment{Warning}{%
        \bigskip
        \begin{mdframed}[%
            topline=false,%
            rightline=false,%
            bottomline=false,%
            innertopmargin=0.4em,%
            innerbottommargin=0.4em,%
            innerrightmargin=0.7em,%
            rightmargin=0.7em,%
            innerleftmargin=0.7em,%
            leftmargin=0.7em,%
            linewidth=.2em,%
            linecolor=warningColor%
        ]
        \color{warningColor}
    }{%
        \end{mdframed}%
        \bigskip
    }

    \usepackage{lipsum}

\begin{document}

\lipsum[1]

\begin{Warning}
    \lipsum
\end{Warning}

\lipsum[1]

\end{document}
share|improve this question
    
if you don't need the page breaking mdframed provides, have a look at the bclogo package - it provides such functionality & has several graphs, including the danger sign, built in (last time I looked the documentation was in french only, but the examples are clear enough). –  prettygully Apr 16 '12 at 1:03
    
I know the bclogo package. Indeed the last development version used mdframed so as to allow page breakings. See this page : melusine.eu.org/syracuse/G/bclogo/dev . Indeed I prefer to do it by hand so as to produce more personal formatting like the one proposed by Marco Daniel. –  projetmbc Apr 16 '12 at 8:23

1 Answer 1

up vote 11 down vote accepted

I provide a solution with TikZ which works similar with framemethod=pstricks. If you are using framemethod=default you must patch internal commands. This based on the implementation. The standard implementation doesn't know "nodes".

To define your requested environment I suggest the following.

First define a tikzstyle which stands for the node placing the danger symbol. Instead of original definition with raisebox you can work with the tikz option scale. In the next step I define a global style by \mdfdefinestyle. The package mdframed offers the option fontcolor which should be used. In your case by setting \color{warningColor} after the beginning of the environment the color modification has no effect if the box is splitted.

To place a node over the left line on every part of the output I use the new options (version 1.5) singleextra, firstextra, secondextra and middleextra. These options added the material to the tikz-environment so that you can modify the output. Therefor I go back to the defined coordinates of mdframed P (left bottom point of the box) and O (right lower point of the box) and compute the position. In the example the position is set to 0.5. You can simple set 1 for the top and 0 for the bottom.

First step:

\tikzset{
  warningsymbol/.style={
      rectangle,
      draw=warningColor,
      fill=white,
      scale=1,
      overlay}
}

Second step:

\mdfdefinestyle{warning}{%
 hidealllines=true,leftline=true,
 skipabove=12,skipbelow=12pt,
 innertopmargin=0.4em,%
 innerbottommargin=0.4em,%
 innerrightmargin=0.7em,%
 rightmargin=0.7em,%
 innerleftmargin=1.7em,%
 leftmargin=0.7em,%
 middlelinewidth=.2em,%
 linecolor=warningColor,%
 fontcolor=warningColor,%
 firstextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(0,\y1)$) 
                           node[warningsymbol] {\danger};},%
 secondextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(0,\y1)$) 
                           node[warningsymbol] {\danger};},%
 middleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(0,\y1)$) 
                           node[warningsymbol] {\danger};},%
 singleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(0,\y1)$) 
                           node[warningsymbol] {\danger};},%
}

With theses modification you get the following output:

The complete code:

\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[x11names, svgnames]{xcolor}
\usepackage[framemethod=tikz]{mdframed}
\usetikzlibrary{calc}
\usepackage{fourier-orns}
\definecolor{warningColor}{named}{Red3}
\tikzset{
  warningsymbol/.style={
      rectangle,
      draw=warningColor,
      fill=white,
      scale=1,
      overlay}
}

\mdfdefinestyle{warning}{%
 hidealllines=true,leftline=true,
 skipabove=12,skipbelow=12pt,
 innertopmargin=0.4em,%
 innerbottommargin=0.4em,%
 innerrightmargin=0.7em,%
 rightmargin=0.7em,%
 innerleftmargin=1.7em,%
 leftmargin=0.7em,%
 middlelinewidth=.2em,%
 linecolor=warningColor,%
 fontcolor=warningColor,%
 firstextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(0,\y1)$) 
                           node[warningsymbol] {\danger};},%
 secondextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(0,\y1)$) 
                           node[warningsymbol] {\danger};},%
 middleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(0,\y1)$) 
                           node[warningsymbol] {\danger};},%
 singleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5*(0,\y1)$) 
                           node[warningsymbol] {\danger};},%
}

\newmdenv[style=warning]{Warning}

\usepackage{lipsum}


\begin{document}
\begin{Warning}
    \lipsum[1]
\end{Warning}
\lipsum[1]

\begin{Warning}
    \lipsum\lipsum[1]
\end{Warning}

\lipsum[1]


\end{document}
share|improve this answer
    
Thanks, this gives an easy to understand example. It should be added to the documentation. –  projetmbc Apr 15 '12 at 17:04
    
@projetmbc: Please see my updated answer. –  Marco Daniel Apr 16 '12 at 9:30
    
Thanks for the explications and this more frendly code. –  projetmbc Apr 16 '12 at 14:11

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.