沿垂直方向的多行曲线文本

沿垂直方向的多行曲线文本

我发现这个渲染这里在这个网站上,但没有解释或可用的示例。我该怎么做?我对 TikZ 非常熟悉,但我很难找到沿垂直方向弯曲的文本,因为大多数弯曲文本的示例都是沿水平方向的。

答案1

CVS 版 PGF 中的新text effects along path修饰几乎可以做到这一点,尽管需要进行一些调整。此修饰可以根据文本中的字符数参数化应用于文本的“效果”(例如缩放或着色)。括号内的文本被视为单个字符:

\documentclass[border=0.125cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.text,math}

\begin{document}

\def\themousestail{%
{Fury said to}
{a mouse, That}
{he met}
{in the}
{house,}
{`Let us}
{both go}
{to law:}
{I will}
{prosecute}
{YOU. ---}
{Come, I'll}
{take no}
{denial;}
{We must}
{have a}
{trial:}
{For}
{really}
{this}
{morning}
{I've}
{nothing}
{to do.'}
{Said the}
{mouse to}
{the cur,}
{`Such a}
{trial,}
{dear sir,}
{With no}
{jury or}
{judge,}
{would be}
{wasting}
{our breath.'}
{`I'll be}
{judge,}
{I'll be}
{jury,'}
{Said}
{cunning}
{old Fury;}
{`I'll try}
{the whole}
{cause,}
{and}
{condemn}
{you}
{to}
{death.'}
}


% The `text effects along path` decoration puts each
% character (or characters within braces) 
% in the text into a TikZ node.

\tikz\draw [decoration={text effects along path, text/.expanded=\themousestail,
  text effects/.cd,
    % parametrize the number of the characters.
    character count=\i, character total=\n,
    % These are the "effects" (node options) used for calculating the width
    % of the bounding box of the character node
    % (i.e., how far to move along the decorated path).
    character widths={rotate=90, scale=1-\i/\n*0.5, execute at begin node=\strut, inner ysep=-0.76ex},% Ugh, -0.76ex by trial and error.
    % `text along path' makes the characters slope with the path
    characters={anchor=base west, scale=1-\i/\n*0.5}}, decorate] 
      (0,0) 
      .. controls ++(1,-1.5) and ++(1,2) .. (0,-5) 
      .. controls ++(-1,-2) and ++(1,1.75) .. (0,-10)
      .. controls ++(-1,-1.75) and ++(0,1) .. (0,-14);


\tikz\draw [decoration={text effects along path, text/.expanded=\themousestail,
text effects/.cd,
    character count=\i, character total=\n,
    character widths={rotate=90, scale=1-\i/\n*0.5, execute at begin node=\strut, inner ysep=-0.76ex},% Ugh, -0.76ex by trial and error.
    % `text along path' makes characters slope with the path.
    characters={text along path, rotate=90, anchor=base west, scale=1-\i/\n*0.5}}, decorate] 
      (0,0) 
      .. controls ++(1,-1.5) and ++(1,2) .. (0,-5) 
      .. controls ++(-1,-2) and ++(1,1.75) .. (0,-10)
      .. controls ++(-1,-1.75) and ++(0,1) .. (0,-14);

\tikz\draw [decoration={text effects along path, text/.expanded=\themousestail,
text effects/.cd,
    character count=\i, character total=\n,
    character widths={rotate=90, scale=1-\i/\n*0.5, execute at begin node=\strut, inner ysep=-0.76ex},% Ugh, -0.76ex by trial and error.
    characters={anchor=base west, scale=1-\i/\n*0.5, evaluate={\c=\i/\n*100;}, text=red!\c!blue}}, decorate] 
      (0,0) 
      .. controls ++(1,-1.5) and ++(1,2) .. (0,-5) 
      .. controls ++(-1,-2) and ++(1,1.75) .. (0,-10)
      .. controls ++(-1,-1.75) and ++(0,1) .. (0,-14);
      
\end{document}

\end{document}

在此处输入图片描述

注意,必须小心路径的构造。如果路径不平滑,一些旋转的线条看起来会有点不对劲:

\documentclass[border=0.125cm]{standalone}

\usepackage{tikz}
\usetikzlibrary{decorations.text}
\begin{document}

\def\themousestail{%
{Fury said to}
{a mouse, That} 
{he met}
{in the} 
{house,}
{``Let us}
{both go}
{to law:}
{I will}
{prosecute}
{YOU.  --- Come,}
{I'll take no}
{denial; We}
{must have a}
{trial:  For}
{really this}
{morning I've}
{nothing}
{to do.''}
{Said the}
{mouse to the}
{cur, ``Such}
{a trial,}
{dear Sir,}
{With}
{no jury}
{or judge,}
{would be}
{wasting}
{our}
{breath.''}
{``I'll be}
{judge, I'll}
{be jury,''}
{Said}
{cunning}
{old Fury:}
{``I'll}
{try the}
{whole}
{cause,}
{and}
{condemn}
{you}
{to}
{death.''}}

% The `text effects along path` decoration puts each
% character (or characters within braces) 
% in the text into a TikZ node.

\tikz\draw [decoration={text effects along path, text/.expanded=\themousestail,
text effects/.cd,
    % These are the node options used for calculating the width of each character
    % (i.e., how far to move along the decorated path).
    character widths={rotate=90, execute at begin node=\strut, inner ysep=-0.875ex},
    % These are the node options applied to each character.
    characters={anchor=base west}}, 
    decorate] 
    (0,0) arc (50:0:3 and 3) arc (0:-40:2 and 3) arc (130:180:2 and 3)  arc (180:230:2 and 3) arc (50:-50:2 and 3);

\tikz\draw [decoration={text effects along path, text/.expanded=\themousestail,
text effects/.cd,
    character widths={rotate=90, execute at begin node=\strut, inner ysep=-0.875ex},
    % `text along path' makes the characters slope with the path
    characters={text along path, rotate=90, anchor=base west}}, decorate] 
    (0,0) arc (50:0:3 and 3) arc (0:-40:2 and 3) arc (130:180:2 and 3)  arc (180:230:2 and 3) arc (50:-50:2 and 3);

\end{document}

在此处输入图片描述

答案2

在此处输入图片描述

制作尾巴的另一种方法是使用Asymptote

// mousetail.asy :
// 
// to get a standalone mousetail.pdf, run
// asy -f pdf mousetail.asy 
//
unitsize(1pt);
import fontsize;
defaultpen(fontsize(10pt));
string[] s={
"Fury said to",
"a mouse, That",
"he met in the",
"house, ``Let us",
"both go to law:",
"I will prosecute",
"YOU.  --- Come,",
"I'll take no",
"denial; We",
"must have a",
"trial:  For",
"really this",
"morning", 
"I've nothing",
"to do.'' Said", 
"the mouse to",
"the cur,",
"``Such a trial,",
"dear Sir,",
"With no", 
"jury or", 
"judge,",
"would be",
"wasting", 
"our",
"breath.''",
"``I'll be",
"judge,",
"I'll be"
,"jury,''",
"Said",
"cun-",
"ning",
"old",
"Fury:",
"``I'll",
"try the",
"whole",
"cause,",
"and",
"con-",
"demn",  
"you",
"to",
"death.''",
};

guide tail=(152,504)..(196,418)..(152,277)..(203,128)..(183,28);
tail=scale(0.95)*tail;
draw(tail,gray(0.6));
real tailsize=arclength(tail);
real dl=tailsize/(s.length-1);
pair linedir;
real t;
Label L;
for(int i=0;i<s.length-1;++i){
  t=arctime(tail,dl*i);          // get the value of time parameter at i-th point 
  linedir=dir(tail,t);           // get the direction of i-th line
  linedir*=(0,1);                // rotate it 90 degrees to get the direction of i-th line
  L=Label(s[i],(0,0),(0,0));     // center i-th Label at the origing
  L=rotate(degrees(linedir))*L;  // rotate it to the angle of i-th line direction
  label(Label(L,t),tail);        // draw i-th label 
}

// draw the last label as a special case 
label(s[s.length-1],point(tail,3.95),SW);

相关内容