2

I am looking to replicate the following artwork with LaTeX: enter image description here

A border resembling a pencil runs along the left-hand side. The pencil is divided into coloured sections corresponding to different pieces of information. Each piece of text is also given a 'reference' (subtitle) of varying lengths. The coloured rounded rectangular tab surrounding each subtitle should also vary in length to fit the entire subtitle.

How can this be achieved with tikz?

The following code by Marco Daniel can be used as a starting point and achieves a similar (but much simplified) effect where a line is drawn along only the left-hand side of a certain piece of text.

\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}

1 Answer 1

6
\documentclass[tikz,border=2.71mm]{standalone}
\usetikzlibrary{decorations.pathmorphing,positioning,shapes.misc}
\begin{document}
\begin{tikzpicture}[font=\sffamily,pics/fancy box/.style={code={
 \path (0,0) coordinate (C0);
 \foreach \Item/\Text [count=\Count starting from 0] in {#1}
 {\pgfmathsetmacro{\mycolor}{{\lstColors}[\Count]}
 \node[rounded rectangle,rounded rectangle left arc=none,fill=\mycolor,anchor=north west] 
 (RR\Count) at (C\Count){\Item};
 \node[anchor=north west,below right=1ex of RR\Count.south west,draw,
 text width=5cm] (T\Count) {\Text};
 \coordinate[below left=1ex of T\Count.south west] (C\the\numexpr\Count+1\relax);
 \fill[\mycolor!50!gray] ([xshift=-1ex]C\Count) rectangle (C\the\numexpr\Count+1\relax);
 \fill[\mycolor] ([xshift=-2ex]C\Count) rectangle ([xshift=-1ex]C\the\numexpr\Count+1\relax);
 \fill[\mycolor!50!gray] ([xshift=-3ex]C\Count) rectangle ([xshift=-2ex]C\the\numexpr\Count+1\relax);
 \ifnum\Count=0
  \path[ball color=\mycolor!50] ([xshift=-3ex]C\Count) to[out=90,in=90]
  (C\Count);
 \fi
 \xdef\myCount{\Count}
 }
 \fill[brown!10,decoration={bumps,segment length=1.96ex}] ([xshift=-3ex]C\the\numexpr\myCount+1\relax) 
  -- ++ (1.5ex,-4ex) coordinate[pos=0.8] (aux1) coordinate[pos=1] (aux2) 
  -- (C\the\numexpr\myCount+1\relax) coordinate[pos=0.2] (aux3)
  -- ++ (0,0.1) decorate {-- ([xshift=-3ex,yshift=1mm]C\the\numexpr\myCount+1\relax)};
 \fill[gray] (aux1) -- (aux2) -- (aux3);
 }}]
 \edef\lstColors{"orange","green","purple","cyan"}
 \pic{fancy box={Reference/Text,Another Reference/Text,More/Body of the text,%
 Reference/Body of the text with a lot of details and the usual blablabla}};
\end{tikzpicture}
\end{document}

enter image description here

3
  • 2
    Welcome back @marmot Aug 14, 2019 at 3:11
  • This is an excellent answer! Is there a way of increasing the gap between the section header and the rounded end of the rectangle and removing the tiny vertical space between the rounded rectangle and pencil?
    – wrb98
    Aug 14, 2019 at 16:55
  • @wrb98 To remove the gap, set the outer sep to 0pt: \node[rounded rectangle,rounded rectangle left arc=none,fill=\mycolor,anchor=north west,outer sep=0pt] (RR\Count) at (C\Count){\Item}; The distances are fixed by the below keys, try e.g. \node[anchor=north west,below right=2ex and 1ex of RR\Count.south west,draw, text width=5cm] (T\Count) {\Text}; \coordinate[below left=2ex and 1ex of T\Count.south west] (C\the\numexpr\Count+1\relax); to double the vertical distance.
    – user194579
    Aug 14, 2019 at 22:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .