左侧有一条类似铅笔的边框。铅笔被分成不同颜色的部分,对应不同的信息。每段文本还被赋予不同长度的“参考”(副标题)。围绕每个副标题的彩色圆角矩形标签的长度也应有所不同,以适合整个副标题。
如何用 tikz 实现这一点?
以下由 Marco Daniel 编写的代码可作为起点,并实现类似(但大大简化)的效果,即仅沿某段文本的左侧绘制一条线。
\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
\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}