I'm hoping to write a custom environment for a double-bracketed "key point" section (see image below). The left and right brackets should be as tall as the text and there should be a little icon with title and text, exactly like in the following example:

enter image description here

Not sure where to start.

  • 4
    Welcome to TeX.SE! I'd like to encourage you to look at the tcolorbox package. – marmot Sep 24 at 20:49
up vote 12 down vote accepted

Just for fun: a tcolorbox based answer.

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\newtcolorbox{lbulbox}[1][]{enhanced,
colback=white,
boxrule=0mm,top=0mm,bottom=0mm,left=2cm,right=4mm,sharp corners,
overlay={%
\draw[ultra thick] ([xshift=2mm]frame.north west)-|(frame.south west)--
([xshift=2mm]frame.south west);
\draw[ultra thick] ([xshift=-2mm]frame.north east)-|(frame.south east)--
([xshift=-2mm]frame.south east);
\draw[thick,white] ([xshift=2mm]frame.north west) -- ([xshift=-2mm]frame.north east)
([xshift=2mm]frame.south west) -- ([xshift=-2mm]frame.south east);
\begin{scope}[shift={([xshift=1cm]frame.west)}]
 \shadedraw[ball color=yellow] (290:0.3) arc(290:-20:0.3) -- ++(0.2,-0.2)
 -- ++(-0.15,-0.15) --cycle;
 \fill[top color=gray,middle color=gray!60!black,bottom color=black,shading angle=-40] (-20:0.3)
  -- ++(0.2,-0.2) -- ++(-0.15,-0.15) -- (290:0.3) -- cycle;
 \foreach \X in {170,140,110}
 {\draw[thick] (\X:0.4) -- (\X:0.6);}
\end{scope}
}}

\begin{document}
\lipsum[1]
\begin{lbulbox}
\textbf{New- and old-style classes.}\par
Old-style classes have only human students. In new-style classes, ducks, koalas
and marmots are welcome. Hibernation needs of marmot students are respected. 
\end{lbulbox}
\lipsum[2]
\end{document}

enter image description here

The following is a quick implementation of what you want without any packages. The syntax is quick and dirty and a mixture of LaTeX and TeX syntax. Every aspect of the environment should be adjustable if you change the used lengths and macros (every one should be commented to make clear what it's used for).

\documentclass[]{article}

\usepackage[]{graphicx}

\makeatletter
\newcommand\Bracket@head[1]{\textbf{#1}} % format the heading
% store the icon
\newsavebox\Bracket@icon
\setbox\Bracket@icon\hbox{\includegraphics[width=1cm]{example-image-duck}}
% the vertical displacement of the icon from the centre of the contents
\newlength\Bracket@iconOffset
\Bracket@iconOffset0pt
% store the contents of the environment
\newsavebox\Bracket@box
% the width it should take as a macro so that the width is evaluated when used,
% this should provide more flexibility
\newcommand\Bracket@totwidth{.95\linewidth}
% the actual contents width (gets calculated)
\newlength\Bracket@width
% the vertical amount of space the brackets are taller than their contents
\newlength\Bracket@vpad
\Bracket@vpad5mm
% the width of the horizontal rules of the brackets
\newlength\Bracket@length
\Bracket@length5mm
% the thickness of the bracket rules
\newlength\Bracket@linewidth
\Bracket@linewidth2pt
% the amount of white space between the left bracket and the logo
\newlength\Bracket@hpadLeft
\Bracket@hpadLeft2.5mm
% the amount of white space between the logo and the contents
\newlength\Bracket@hpadIcon
\Bracket@hpadIcon2.5mm
% the amount of white space between the right bracket and the contents
\newlength\Bracket@hpadRight
\Bracket@hpadRight5mm
% the vertical white space added above the whole environment
\newlength\Bracket@aboveSkip
\Bracket@aboveSkip1ex
% the vertical white space added below the whole environment
\newlength\Bracket@belowSkip
\Bracket@belowSkip1ex
% the definition of the environment
\newenvironment{Bracket}[1]
  {%
    \Bracket@width\Bracket@totwidth
    \advance\Bracket@width-\Bracket@hpadRight
    \advance\Bracket@width-\Bracket@hpadLeft
    \advance\Bracket@width-\Bracket@hpadIcon
    \advance\Bracket@width-\wd\Bracket@icon
    \advance\Bracket@width-2\Bracket@linewidth
    \setbox\Bracket@box\vbox\bgroup
      \hsize\Bracket@width
      \linewidth\hsize
      \noindent
      \Bracket@head{#1}\par
      \@afterindentfalse
      \@afterheading
  }
  {%
    \egroup
    \par
    \vskip\Bracket@aboveSkip
    \noindent
    \null
    \hskip\dimexpr(\linewidth-\Bracket@totwidth)/2\relax
    \rlap
      {%
        \vrule height \dimexpr\ht\Bracket@box+\Bracket@vpad
               depth \dimexpr\dp\Bracket@box+\Bracket@vpad
               width \Bracket@linewidth
        \rlap
          {%
            \rlap
              {%
                \raisebox{\dimexpr\ht\Bracket@box+\Bracket@vpad\relax}
                  {%
                    \vrule height 0pt
                           depth \Bracket@linewidth
                           width \Bracket@length
                  }%
              }%
            \raisebox{-\dimexpr\dp\Bracket@box+\Bracket@vpad\relax}
              {%
                \vrule height \Bracket@linewidth
                       depth 0pt
                       width \Bracket@length
              }%
          }%
        \hskip\Bracket@hpadLeft
        \raisebox
          {%
            \dimexpr
              .5\ht\Bracket@box-.5\dp\Bracket@box
              -.5\ht\Bracket@icon+.5\dp\Bracket@icon
              +\Bracket@iconOffset
            \relax
          }
          {\usebox\Bracket@icon}%
        \hskip\Bracket@hpadIcon
        \usebox\Bracket@box
        \hskip\Bracket@hpadRight
        \vrule height \dimexpr\ht\Bracket@box+\Bracket@vpad
               depth \dimexpr\dp\Bracket@box+\Bracket@vpad
               width \Bracket@linewidth
        \rlap
          {%
            \hskip-\Bracket@linewidth
            \llap
              {%
                \raisebox{\dimexpr\ht\Bracket@box+\Bracket@vpad\relax}
                  {%
                    \vrule height 0pt
                           depth \Bracket@linewidth
                           width \Bracket@length
                  }%
              }%
            \llap
              {%
                \raisebox{-\dimexpr\dp\Bracket@box+\Bracket@vpad\relax}
                  {%
                    \vrule height \Bracket@linewidth
                           depth 0pt
                           width \Bracket@length
                  }%
              }%
          }%
      }%
    \par
    \vskip\Bracket@belowSkip
  }
\makeatother

\usepackage{duckuments}% only for \blindduck

\begin{document}
\blindduck[1]
\begin{Bracket}{New- and old-style classes}
  \blindduck[2]
\end{Bracket}
\noindent
\blindduck[3]
\end{document}

enter image description here

EDIT: Allows a total width greater than the surrounding \linewidth without overfull boxes.

I should mention that the result is not page breakable. If this is required, tcolorbox can be page broken if set up correctly, so take a look at @marmot's answer (this doesn't claim that the way @marmot set up tcolorbox is page breakable, I didn't check this, so it might be breakable, but might as well be not).

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.