想象一下,在一条薄纸条上写上文字,像丝带一样缠绕在身上。我认为这可能可以通过 tikz 实现。我想要的是满足三个属性的东西:
- 用一种颜色(例如黄色)突出显示文本的背景。
- 每行的背景都是可见的(因此背景不会合并成一个大的彩色块)。
- 黄色后面还有一个彩色矩形(比如灰色),它以一定角度连接换行符的末尾和下一行的开头。在 MWE 中,这个属性为 3 的矩形从文本中的 A 开始,到 B 结束。
以下 MWE 仅满足属性 1。
\documentclass{article}
\usepackage{tikz}
\newcommand\ribbonText[1]{%
\tikz\node[rectangle, fill=yellow, text width=31mm]{#1};%
}%
\begin{document}
\ribbonText{hello world this is some dummy text}
\end{document}
编辑 Ignasi 的回答有一定道理,但是难道不可能在 tikz 节点中自动找到换行符吗?
答案1
我怀疑这有点矫枉过正。而且倾斜角色并不总是有效。
\documentclass[tikz,border=0.125cm]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\foreach \i in {1,...,2}
\path [left color=gray, right color=gray!50!black, shift=(270:\i*2)]
(-2,0)
to [bend left, out=300, in=270, looseness=.5] (2,-2) -- (2,-1)
to [bend left, out=90, in=120, looseness=.5] (-2,1) -- cycle;
\foreach \i in {1,...,3}
\path [left color=yellow, right color=yellow!50!orange, shift=(270:\i*2)]
(2,0)
to [bend left, out=270, in=270, looseness=.5] (-2,0) -- (-2,1)
to [bend left, out=90, in=90, looseness=.5] ( 2,1) -- cycle;
\tikzset{%
banner text/.style={%
decoration={text effects along path,
text={#1}, text align=center,
text effects/.cd,
character count=\i, character total=\n,
characters={inner sep=0pt,
anchor=base,
font=\huge,
yslant=-(\i-\n/2)/20
},
}, decorate,
}
}
\foreach \t [count=\i] in {Hello world, this is some, dummy text}
\path [banner text/.expanded=\t, shift=(270:\i*2-.25)]
(-2,0)
to [bend left, out=90, in=90, looseness=.5] (2,0) ;
\end{tikzpicture}
\end{document}
答案2
如果允许手动断线的话我知道怎么做;-)
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{positioning,backgrounds}
\begin{document}
\begin{tikzpicture}[ribbon/.style={rectangle, fill=yellow, text width=31mm, align=center}, back/.style={fill=gray}]
\node[ribbon](a){Hello, world};
\node[ribbon, below=5mm of a] (b){this is some};
\node[ribbon, below=5mm of b] (c){dummy text};
\begin{scope}[on background layer]
\foreach \i/\j in {a/b, b/c}
\fill[back] (\i.north east)--(\i.south east)--(\j.south west)--(\j.north west)--cycle;
\end{scope}
\end{tikzpicture}
\end{document}