如何通过简单的 TikZ 命令实现这一点?

如何通过简单的 TikZ 命令实现这一点?

我有一个PStricks代码,并在 Paint 中做了一些设计,然后使用 转换为 LaTeX 代码Inkscape。这是我的 MWE:

 \documentclass{standalone}
 \usepackage{graphicx,xcolor}
 \usepackage[svgnames,pdf]{pstricks}

 \begin{document}
 \psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
 \begin{pspicture}(1122.51968504,793.7007874)
 {
 \newrgbcolor{curcolor}{0.0 0.18 0.39}
 \pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]
 {
 \newpath
 \moveto(0.21430135,613.28571969)
 \lineto(0.21430135,791.28569953)
 \lineto(564.28569449,791.28569953)
 \lineto(1124.35710236,791.28569953)
 \lineto(1124.35710236,752.28569953)
 \curveto(1124.35710236,726.58745197)(1124.0120315,713.28570709)(1123.34551181,713.28570709)
 \curveto(1122.78901417,713.28570709)(1110.33327874,714.38343307)(1095.66610394,715.72512756)
 \curveto(1047.23973543,720.15496063)(1031.79420472,720.78568819)(971.7463937,720.78568819)
 \curveto(911.02805669,720.78568819)(895.60410709,720.11690079)(854.04661417,715.68215433)
 \curveto(798.76191496,709.78253858)(761.94504567,702.99148346)(705.42568819,688.26837165)
 \curveto(627.87208819,668.06585197)(567.87405354,645.8808189)(430.12792441,586.47367559)
 \curveto(335.62666583,545.71717795)(298.91214614,530.42936693)(255.39842646,513.7168252)
 \curveto(195.55985008,490.73431181)(135.52230803,470.60330079)(75.53238803,453.40648819)
 \curveto(48.22059969,445.57723465)(8.88333846,435.28569449)(6.26950677,435.28569449)
 \lineto(0.21430135,435.28569449)
 \closepath
 }
 }
 \end{pspicture}
 \end{document}

在此处输入图片描述

答案1

我假设这张图片是一些插图,所以精确的坐标不是最重要的,可以稍后通过试验进行调整。画直线很简单,对于曲线我建议使用controls宏:

(<coordinate 1>) .. controls + (<control point 1>) 
                         and + (<control point 2>) .. (<coordinate 2>)

其中符号+表示相对于坐标的位置。

在此处输入图片描述

\documentclass[tikz,margin=0pt]{standalone}
\definecolor{curcolor}{rgb}{0,0.18,0.39}

\begin{document}
    \begin{tikzpicture}
\fill[curcolor]
    (0,0) -| (12,-1.2)
    .. controls ++ (-0.5,0.1) and ++ (1,0) .. (10,-1)
    .. controls ++ (-3,0) and ++ (4,1) .. (0,-5) -- cycle;
\path(0,0) rectangle + (12,-8);% if needed
    \end{tikzpicture}
\end{document}

答案2

Inkscape 导出的 PSTricks 太垃圾了!

\documentclass{standalone}
\usepackage{pstricks}
\definecolor{curcolor}{rgb}{0.0,0.18,0.39}

\begin{document}
\psset{unit=.5pt}
\begin{pspicture}(1122,793)
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]{
 \psline(0,435)(0,791)(1124,791)(1124,713)(1122,713)
 \psbezier(1110,714)(1095,715)(1047,720)(1031,720)%
   (895,720)(854,715)(798,709)(761,702)(705,688)(627,668)(567,645)(430,586)%
   (335,545)(298,530)(255,513)(195,490)(135,470)(75,453)(48,445)(8,435)(0,435)}
\end{pspicture}

\qquad

\begin{pspicture}(1122,793)
\newrgbcolor{curcolor}{0.0 0.18 0.39}
\pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]{
\psline(0,435)(0,791)(1124,791)(1124,713)(1122,713)
 \pscurve(854,715)(627,668)(430,586)(335,545)(255,513)(135,470)(0,435)}
\end{pspicture}

\end{document}

在此处输入图片描述

在此处输入图片描述

答案3

这个答案并不试图改善形状,而是解释从pstricks到 TikZ 的翻译:

  • 尺寸不需要指定,在很多情况下,TikZ 可以根据图片中的元素计算边界框。

  • color可以使用(或)包来定义颜色xcolor

    \definecolor{curcolor}{rgb}{0, .18, .39}
    
  • 单位设置

    \psset{xunit=.5pt,yunit=.5pt,runit=.5pt}
    

    x可以用选项和来完成y,但runit不使用:

    \begin{tikzpicture}[x=.5pt, y=.5pt]
    
  • 路径由以下项填充\path[fill=curcolor] ...;或更短:

    \fill[curcolor] ...;
    

    默认为实心填充。除非draw添加,否则不会绘制线条。这包括:

    \pscustom[linestyle=none,fillstyle=solid,fillcolor=curcolor]{
      \newpath
      ...
    }
    
  • \moveto(12, 34)通过指定坐标隐式完成:

    (12, 34)
    
  • \lineto(56, 78)变成:

    -- (56, 78)
    
  • \curveto(1, 2)(3, 4)(5, 6)由以下指定controls(参见 Zarko 的回答)。前两个点是控制点:

    .. controls (1, 2) and (3, 4) .. (5, 6)
    
  • \closepath

    -- cycle
    

完整示例:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{xcolor}

\definecolor{curcolor}{rgb}{0, .18, .39}

\begin{document}
\begin{tikzpicture}[x=.5pt, y=.5pt]
  \fill[curcolor]
    (0.21430135,613.28571969)
    -- (0.21430135,791.28569953)
    -- (564.28569449,791.28569953)
    -- (1124.35710236,791.28569953)
    -- (1124.35710236,752.28569953)
    .. controls (1124.35710236,726.58745197) and (1124.0120315,713.28570709)
                .. (1123.34551181,713.28570709)
    .. controls (1122.78901417,713.28570709) and (1110.33327874,714.38343307)
                .. (1095.66610394,715.72512756)
    .. controls (1047.23973543,720.15496063) and (1031.79420472,720.78568819)
                .. (971.7463937,720.78568819)
    .. controls (911.02805669,720.78568819) and (895.60410709,720.11690079)
                .. (854.04661417,715.68215433)
    .. controls (798.76191496,709.78253858) and (761.94504567,702.99148346)
                .. (705.42568819,688.26837165)
    .. controls (627.87208819,668.06585197) and (567.87405354,645.8808189)
                .. (430.12792441,586.47367559)
    .. controls (335.62666583,545.71717795) and (298.91214614,530.42936693)
                .. (255.39842646,513.7168252)
    .. controls (195.55985008,490.73431181) and (135.52230803,470.60330079)
                .. (75.53238803,453.40648819)
    .. controls (48.22059969,445.57723465) and (8.88333846,435.28569449)
                .. (6.26950677,435.28569449)
    -- (0.21430135,435.28569449)
    -- cycle
  ;
\end{tikzpicture}
\end{document}

结果

答案4

pstricks 和 Ti 之间存在简单的对应关系,尽管我认为不是绝对精确的。Z 命令。(X) \lineto (Y)转换为(X) -- (Y)(在\draw ...环境中)并(X) \curveto (Y) (Z) ...变成(X) -- plot coordinates {(Y)(Z)...}。所以

 \documentclass{standalone}
 \usepackage{tikz}

 \begin{document}
 \begin{tikzpicture}
 \definecolor{DeepBlue}{rgb}{0,0.18,0.39}
 \fill[DeepBlue,smooth] (0.00214, 6.13286) -- (0.00214, 7.91286) -- 
 (5.64286, 7.91286) -- (11.2436,   7.91286)--  (11.2436, 7.52286) -- (11.2436, 7.26587)--  plot coordinates{(11.2401,   7.13286) (11.2335, 7.13286) (11.2279, 7.13286) (11.1033,   7.14383) (10.9567, 7.15725) (10.4724, 7.20155) (10.3179,   7.20786) (9.71746, 7.20786) (9.11028, 7.20786) (8.95604,   7.20117) (8.54047, 7.15682) (7.98762, 7.09783) (7.61945,   7.02991) (7.05426, 6.88268) (6.27872, 6.68066) (5.67874,   6.45881) (4.30128, 5.86474) (3.35627, 5.45717) (2.98912,   5.30429) (2.55398, 5.13717) (1.9556, 4.90734) (1.35522,   4.70603) (0.75532, 4.53406)}
-- (0.48221, 4.45577) -- (0.08883,   4.35286) -- (0.0627, 4.35286) -- (0.00214, 4.35286);
 \end{tikzpicture}
 \end{document}

生成的结果非常接近您的屏幕截图。其他平滑轮廓的选项如下:这里

在此处输入图片描述

但因为你似乎是用 Inkscape 生成的代码,你可以看看自动转换。我发布此帖是因为我无法获得svg2tikz安装。(另请注意,我划分了您的坐标,以使它们均匀扎布尔。)

另一个可能更漂亮的方法是让你最喜欢的计算机代数系统找到轮廓的参数化。这会产生

 \documentclass{standalone}
 \usepackage{tikz}

 \begin{document}
 \begin{tikzpicture}
 \definecolor{DeepBlue}{rgb}{0,0.18,0.39}
 \draw[domain=0.00214:11.22789,smooth,variable=\x,fill=DeepBlue] plot ({\x}, 
 {-6.9158922189150305 +1.866300006839081*\x - 
 0.10927417962900386*
  (-104.05234359678035 + 
   exp(0.6230737205554076*\x))*
  (1 - 0.14157109964187192*\x + 
   0.005184318196230514*\x^2)}) -- (11.22789,7.91286)--(0.00214, 7.91286) --cycle;  
 \end{tikzpicture}
 \end{document}

在此处输入图片描述

当然,人们也可以调整曲线,即移动或重新缩放曲线,从而使参数化变得更漂亮。

相关内容