LaTeX 中沿皮亚诺曲线的文本作为封面

LaTeX 中沿皮亚诺曲线的文本作为封面

下午好,

我试图沿着皮亚诺曲线写文字,并查找了如何使用 TikZ 绘制皮亚诺曲线。

但是,我不知道如何将文本放置在皮亚诺曲线上。我陷入困境,希望有人能给我指明正确的方向。

这是我用来生成皮亚诺曲线的代码。我真的希望我能更好地理解 TikZ,它是一个非常强大的软件包。

\documentclass[12pt]{article}

\usepackage{tikz}
\usepackage{ifthen}

\usepackage[position=top,labelformat=empty]{subfig}
\newdimen\HilbertLastX
\newdimen\HilbertLastY
\newcounter{HilbertOrder}

\def\DrawToNext#1#2{%
   \advance \HilbertLastX by #1
   \advance \HilbertLastY by #2
   \pgfpathlineto{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}
   % Alternative implementation using plot streams:
   % \pgfplotstreampoint{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}
}

% \Hilbert[right_x,right_y,left_x,left_x,up_x,up_y,down_x,down_y]
\def\Hilbert[#1,#2,#3,#4,#5,#6,#7,#8] {
  \ifnum\value{HilbertOrder} > 0%
     \addtocounter{HilbertOrder}{-1}
     \Hilbert[#5,#6,#7,#8,#1,#2,#3,#4]
     \DrawToNext {#1} {#2}
     \Hilbert[#1,#2,#3,#4,#5,#6,#7,#8]
     \DrawToNext {#5} {#6}
     \Hilbert[#1,#2,#3,#4,#5,#6,#7,#8]
     \DrawToNext {#3} {#4}
     \Hilbert[#7,#8,#5,#6,#3,#4,#1,#2]
     \addtocounter{HilbertOrder}{1}
  \fi
}


% \hilbert((x,y),order)
\def\hilbert((#1,#2),#3){%
   \advance \HilbertLastX by #1
   \advance \HilbertLastY by #2
   \pgfpathmoveto{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}
   % Alternative implementation using plot streams:
   % \pgfplothandlerlineto
   % \pgfplotstreamstart
   % \pgfplotstreampoint{\pgfqpoint{\HilbertLastX}{\HilbertLastY}}
   \setcounter{HilbertOrder}{#3}
   \Hilbert[1mm,0mm,-1mm,0mm,0mm,1mm,0mm,-1mm]
   \pgfusepath{stroke}%
}

\begin{document}
\begin{figure}%
    \centering
    % draw Hilbert curves of order n=1,...,5
    % Warning! Curves with order > 6 may crash TeX
    \subfloat[$n=1$]{\tikz[scale=18] \hilbert((0mm,0mm),1);}~~
    \subfloat[$n=2$]{\tikz[scale=6] \hilbert((0mm,0mm),2);}~~
    \subfloat[$n=3$]{\tikz[scale=2.6] \hilbert((0mm,0mm),3);}~~
    \subfloat[$n=4$]{\tikz[scale=1.2] \hilbert((0mm,0mm),4);}~~
    \subfloat[$n=5$]{\tikz[scale=0.58] \hilbert((0mm,0mm),5);}%
\end{figure}%

\end{document} 

澄清一下:我不想让文本位于路径上方,我希望文档沿着皮亚诺填充曲线路径书写。我知道如何制作一些形状。

我希望有人能帮助我找到解决方案。

这是类似的例子,是一些沿路径的文本。我只是不知道如何将其应用于皮亚诺曲线。

(您需要使用XeLaTeX来加载这个,我正在使用一些奇怪的字体,而且也是泰语,所以这个例子是泰语的

\documentclass[10pt,a4paper]{article}

\usepackage[a4paper,top=2cm, bottom = 2cm, left = 2cm, right = 2cm, margin = 2cm, headsep = .5cm,headheight=50pt,xetex]{geometry}\usepackage[main = english,thai]{babel}


\usepackage[cmyk]{xcolor}
\usepackage{tikz}
\usetikzlibrary{decorations.text}
\usepackage{txfonts,pxfonts}

\usepackage[no-math]{fontspec} 
\begin{document}


\resizebox{\textwidth}{\textwidth}{%

\begin{tikzpicture}[
    width = \textwidth,
  decoration={
    reverse path,
    text effects along path,
    text={Let me know when you are able to use word to do this and I will stop using LaTeX and I will promise you I will never talk about it again. However if you ever think you will be able to do somethign like this in word... haahaha, 
    good luck being able to get it done in a feasable amount of time. },
    text effects/.cd,
      text along path,
      character count=\i, character total=\n, color=green!50!red,
      characters={scale=0.5-0.45*\i/\n}
    }
]
\draw [decorate] (0,0) 
    \foreach \i [evaluate={\r=(\i/3000)^2+ sin(3*\i)*cos(2*\i)/10;}] in {0,5,...,2800}{ -- (\i:\r)}; 
\end{tikzpicture}

}

\end{document}

EDIT1:澄清一些观点以使问题更清晰,并添加了一个额外的例子。

EDIT2:一些格式错误(抱歉,我是 stackexchange 新手)。

答案1

手册中有希尔伯特曲线的明确构造。我所做的只是复制示例代码。

\documentclass[12pt]{article}

\usepackage{tikz,lipsum}
\usetikzlibrary{lindenmayersystems}
\usetikzlibrary{decorations.text}

\begin{document}
\pgfdeclarelindenmayersystem{Hilbert curve}{
  \symbol{X}{\pgflsystemdrawforward}
  \symbol{+}{\pgflsystemturnright} % Explicitly define + and - symbols.
  \symbol{-}{\pgflsystemturnleft}
  \rule{A -> +BX-AXA-XB+}
  \rule{B -> -AX+BXB+XA-}
}
\tikz
    \draw[
        rounded corners=10pt,scale=5,
        decoration={
            text along path,
            text={Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui.},
        },
        decorate,
        lindenmayer system={
            Hilbert curve, axiom=A, order=4, angle=90
        },
    ]
    lindenmayer system
;

\end{document}

答案2

作为后续行动,并遵循@Symbol 1 解决方案,我想发布我想要的完整解决方案,以防它对其他人有用。因为我认为它可能更“通用”,并且它涉及一些其他 tikz 键。

圆角似乎会造成很大的麻烦,这就是为什么我必须把它去掉才能升级到 5 号订单

要将重复文本更改为自定义长文本,请删除“重复文本”键并将中文文本替换为您自己的长文本

(我使用 XeLaTeX 是因为有中文“新年快乐”文字,但这可以轻松更改)

% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = XeLaTeX
\documentclass[10pt]{standalone}

\usepackage{fontspec}

\usepackage{xeCJK}

\usepackage{xcolor} %To use the colors
\usepackage{tikz}
\usetikzlibrary{lindenmayersystems}
\usetikzlibrary{decorations.text,math} % math library to evaluate the color transition (key evaluate on tikz) 

\definecolor{chinesegolden}{RGB}{%
246,180,72}
\definecolor{chinesered}{RGB}{%
198, 0, 20}

\begin{document}
\pgfdeclarelindenmayersystem{Hilbert curve}{
  \symbol{X}{\pgflsystemdrawforward}
  \symbol{+}{\pgflsystemturnright} % Explicitly define + and - symbols.
  \symbol{-}{\pgflsystemturnleft}
  \rule{A -> +BX-AXA-XB+}
  \rule{B -> -AX+BXB+XA-}
}



\begin{tikzpicture}[
  scale=2, decoration={
    text effects along path,
    text={ 新 年 快 乐 ! 新 年 快 乐 ! ! !},
        text effects/.cd,
        repeat text, %Fills the whole curve
      character count=\i, character total=\n,
      characters={evaluate={\c=\i/\n*100;}, 
                scale=0.3, 
            text along path,
                text ={chinesered!\c!chinesegolden}
            }
    }
]    
\path[
        decorate, %text effects={group letters},
        lindenmayer system={
            Hilbert curve, axiom=A, order = 5, angle=90 %Order 5 takes a while to render
        },
    ]
    lindenmayer system;
\end{tikzpicture}

\end{document}

5 阶 - 带文本的希尔伯特曲线

相关内容