我最喜欢的诗人之一可能是纪尧姆·阿波利奈尔。他的故事和与毕加索的亲密关系使他成为先驱。书法不断尝试将诗歌与视觉融合。我想知道我们如何才能在 TikZ 中重现
答案1
这只是提到 Ti钾Z 已经内置了大量可应用于路径的技巧。这是一个非常基本的示例。(是的,我知道我不是诗人。;-)
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.text}
\begin{document}
\begin{tikzpicture}
\def\mypath{
(-2,0) to[bend right=10] (0,5.1)
to[bend right=10] (2,0) -- (1.5,0) -- (0.8,1) -- (-0.8,1) -- (-1.5,0) -- cycle}
\draw \mypath;
\path[decorate,decoration={text along path,
text={In Paris there is a tower and beneath it there grows a flower. And often
on Mondays there is a shower.}}] \mypath;
\end{tikzpicture}
\end{document}
我认为最令人惊叹的工具不是来自 pgfmanual,而是由于Paul Gaborit 的精彩回答。您基本上定义轮廓,宏会处理其余部分。(当然,您可能希望最后稍微调整一下,但它开箱即用的功能令人惊叹。)
\documentclass{standalone}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{shapepar}
\usepackage{microtype}
\usepackage{lipsum}
\usepackage{tikz}
\usetikzlibrary{calc,fit,intersections}
\def\shapeparnodeaccuracy{2}
\newcommand\shapeparnode[6][]{
% 6 parameters:
% style for node (default:empty),
% h margin, v margin, left path, right path, text (just one paragraph!)
% name left and right paths and compute there bounding boxes
\begin{scope}[local bounding box=leftbb]
\path[name path global=left,xshift=#2] #4;
\end{scope}
\node[inner ysep=-#3,inner xsep=0pt,fit=(leftbb)](leftbb){};
\begin{scope}[local bounding box=rightbb]
\path[name path global=right,xshift=-#2] #5;
\end{scope}
\node[inner ysep=-#3,inner xsep=0pt,fit=(rightbb)](rightbb){};
% global bounding box
\path let
\p1=(leftbb.north west), \p2=(leftbb.south west),
\p3=(rightbb.north east), \p4=(rightbb.south east)
in
\pgfextra{
\pgfmathsetmacro{\ymin}{(\y1 < \y3) ? \y1 : \y3}
\pgfmathsetmacro{\ymax}{(\y2 > \y4) ? \y2 : \y4}
\typeout{ymin \ymin}
\typeout{ymax \ymax}
} node[inner sep=0,fit={(\x1,\ymin pt)(\x3,\ymax pt)}](mybb){};
% compute nb steps
\path let \p1=(mybb.north), \p2=(mybb.south) in
\pgfextra{
\pgfmathsetmacro{\fnthght}{1em/\shapeparnodeaccuracy}
\pgfmathtruncatemacro{\nbsteps}{(\y1-\y2)/\fnthght}
\xdef\nbsteps{\nbsteps}
\typeout{nb steps \nbsteps}
};
% horizontal references
\path (mybb.north) -- (mybb.south)
\foreach \cnt in {0,1,...,\nbsteps}{
\pgfextra{\pgfmathsetmacro{\pos}{\cnt/\nbsteps}}
coordinate[pos=\pos] (ref \cnt)
};
% left and right boundaries coordinates
\foreach \cnt in {0,1,...,\nbsteps}{
% an horizontal line from left to right
\path[name path=ltor]
(mybb.west |- ref \cnt) -- (mybb.east |- ref \cnt);
% same line from right to left
\path[name path=rtol]
(mybb.east |- ref \cnt) -- (mybb.west |- ref \cnt);
% left boundary
\path[name intersections={of=rtol and left,by={l \cnt},sort by=rtol}];
% right boundary
\path[name intersections={of=ltor and right,by={r \cnt},sort by=ltor}];
}
% start point (and initial value of boundshape)
\path let \p1=(l 0) in
\pgfextra{
\pgfmathsetmacro{\xstart}{\x1}
\xdef\boundshape{{0}{0}b{\xstart}}
\xdef\xmin{\xstart}
\xdef\xmax{\xstart}
};
% top and bottom
\path let \p1=(l 0), \p2=(l \nbsteps) in
\pgfextra{
\pgfmathsetmacro{\ystart}{\y1}\xdef\ystart{\ystart}
\pgfmathsetmacro{\yending}{\y2}\xdef\yending{\yending}
};
% incremental definition of boundshape
\foreach \cnt in {0,1,...,\nbsteps}{
\path let \p1=(l \cnt), \p2=(r \cnt) in
\pgfextra{
\pgfmathsetmacro{\start}{\x1}
\pgfmathsetmacro{\len}{\x2-\x1}
\pgfmathsetmacro{\ypos}{\cnt/\nbsteps*(\ystart - \yending)}
{\let\\=\relax \xdef\boundshape{\boundshape\\{\ypos}t{\start}{\len}}}
\pgfmathsetmacro{\xmin}{(\xmin < \start) ? \xmin : \start}
\xdef\xmin{\xmin}
\pgfmathsetmacro{\xmax}{(\xmax > \start + \len) ? \xmax : \start + \len}
\xdef\xmax{\xmax}
};
}
% draw the node with text in a shapepar
\pgfmathsetmacro{\ymax}{\ystart - \yending}
{\let\\=\relax \xdef\boundshape{\boundshape\\{\ymax}e{0}}}
\node[#1,text width=\xmax pt - \xmin pt,align=flush left,
anchor=north west,inner sep=0]
at (mybb.north west -| \xmin pt,0)
{\Shapepar[1pt]{\boundshape}#6\par};
}
\def\mytext{In Paris there is a tower and beneath it there grows a flower.}
\begin{document}%
\begin{tikzpicture}
\def\pathone{(0,1) -- (-0.8,1) -- (-1.5,0) --
(-2,0) to[bend right=10] (0,5.1)}
\def\pathtwo{(0,5.1)
to[bend right=10] (2,0) -- (1.5,0) -- (0.8,1) -- (-0.8,1)}
\fill[top color=lime,bottom color=orange,middle color=yellow,draw=white]
\pathone -- \pathtwo -- cycle;
\def\pathone{(0,1) -- (-0.8,1) -- (-1.5,0) --
(-1.6,0) to[bend right=10] (0,4.1)}
\def\pathtwo{(0,4.1)
to[bend right=10] (1.6,0) -- (1.5,0) -- (0.8,1) -- (-0.8,1)}
\shapeparnode[text=black,font=\footnotesize\scshape]
{0.1em}{0.1em}{\pathone}{\pathtwo}{\mytext}%
%\draw[orange] \pathone;
%\draw[orange] \pathtwo;
\end{tikzpicture}
\end{document}
答案2
\documentclass[pstricks,convert]{standalone}
\usepackage[T1]{fontenc}
\usepackage{mathptmx}
\usepackage{pst-plot}
\usepackage{pst-text}
\newdimen\MyDim \MyDim=30pt
\makeatletter
\def\doPerChar#1#2\@nil{%
\CharacterAction{#1}%
\ifx\relax#2\relax\else\doPerChar#2\@nil\fi}
\def\perChar#1{\doPerChar#1\@nil}
\def\CharacterAction#1{%
\fontsize{\MyDim}{1.1\MyDim}\selectfont#1%
\global\advance\MyDim by -0.175pt}
\makeatother
\begin{document}
\begin{pspicture}(-5,-5)(5,5)
\pstextpath{%
\parametricplot[linestyle=none,plotpoints=5000,algebraic,unit=0.3]
{50}{0}[/A 5e-3 def ]{A*(cos(t)+t^2*sin(t)) | A*(sin(t)-t^2*cos(t))}}{\perChar{%
{$a$}{$\!^2$}+{$b$}{$\!^2$}={$c$}{$\!^2$}~is~from~Pythagoras~%
who~lived~in~Greek.~{$\sin^2x+\cos^2x=1$}~is~also~from~him~and~%
the~same~in~geometry~\ldots}}
\end{pspicture}
\end{document}