如何使用 Tikz \shade 命令来实现类似 3D 的效果

如何使用 Tikz \shade 命令来实现类似 3D 的效果

我有一些图形,我相信它们足以展示我的需要,但我想更进一步,我想知道在 \shade[] 命令中可以使用什么样的设置来创建 3D 效果。

MWE 是红灯的绘图,我希望它看起来像这个 png 图形

红灯

\documentclass[11pt,a4paper]{article}
\usepackage{tikz}
\begin{document}
            \begin{tikzpicture}
            \draw[rounded corners,fill=yellow!80!brown] (-1,4)rectangle++ (2.5,3);
            \draw[rounded corners,fill=gray] (-0.8,4.2)rectangle++ (2.1,2.6);
            \draw[fill=red] (0.25,6.3)circle [radius=8pt];
            \draw[fill=yellow] (0.25,5.5)circle [radius=8pt];
            \draw[fill=green] (0.25,4.7)circle [radius=8pt];
            \draw[fill=yellow!80!brown] (0,0)rectangle++ (0.5,4);
            \end{tikzpicture}
\end{document}

答案1

这是我在 20 + 10 分钟内能够完成的事情...剩下的微调将花费更长的时间。编辑:添加了阴影。

在此处输入图片描述

\documentclass[tikz,border=3.14pt]{standalone}
\usetikzlibrary{shadings}

\newcommand{\translight}[1]{\begin{scope}[#1]
\shade[top color=gray,bottom color=black] (0,0) -- ++ (1.9,0) -- ++ (0,-1.9) -- ++(-0.8,0) to
[out=90,in=-90] ++(-1.1,1.7) -- cycle;
\draw[fill=black!80!gray] (1.9,0.3) -- ++(0.2,0) -- ++(0,-2.4) -- ++(-0.2,0) -- cycle;
\end{scope}
}
\newcommand{\bulb}[2][]{\begin{scope}[#1]
\draw[thick,fill=black!80!gray] (-1.2,-1.4) coordinate (bl) rectangle ++(2.4,2.2)
coordinate (tr);
\shade[ball color=#2] (0,-0.2) circle (0.9);
\draw[fill=black!97!gray] (bl) -- ++ (-0.12,-0.12) -- ++(2.64,0) -- (bl-|tr) -- cycle;
\draw[fill=black!98!gray] (bl-|tr) -- ++ (0.12,-0.12) -- ++(0,2.44) -- (tr) -- cycle;
\draw[fill=black!50!gray] (tr-|bl) -- ++ (-0.12,0.12) -- ++(2.64,0) -- (tr) -- cycle;
\draw[fill=black!50!gray] (tr-|bl) -- ++ (-0.12,0.12) -- ++(0,-2.44)
-- (bl) -- cycle;
\end{scope}
}

\begin{document}
\begin{tikzpicture}
\draw[fill=black!90!gray] (-1.5,-4.3) rectangle (1.5,3.6);
\bulb[shift={(0,2.4)}]{orange!10!red}
\bulb[shift={(0,0)}]{orange!50!yellow}
\bulb[shift={(0,-2.4)}]{green!70!black}
\translight{shift={(-3.6,3.2)}}
\translight{shift={(-3.6,0.7)}}
\translight{shift={(-3.6,-1.9)}}
%\translight{shift={(3.6,3.2)},xscale=-1}
\begin{scope}[shift={(3.6,3.2)},xscale=-1]
\draw[fill=black!80!gray] (1.9,0.3) -- ++(0.2,0) -- ++(0,-2.4) -- ++(-0.2,0) -- cycle;
\shade[top color=gray,bottom color=black,clip] (0,0) -- ++ (1.9,0) -- ++ (0,-1.9) -- ++(-0.8,0) to
[out=90,in=-90] ++(-1.1,1.7) -- cycle;
\fill[gray!20!black,opacity=0.3] (1.9,0) -- ++(-0.2,0) -- ++ (-1.8,-1.8) -- ++ (2,0) -- cycle;
\end{scope}
%\translight{shift={(3.6,0.7)},xscale=-1}
\begin{scope}[shift={(3.6,0.7)},xscale=-1]
\draw[fill=black!80!gray] (1.9,0.3) -- ++(0.2,0) -- ++(0,-2.4) -- ++(-0.2,0) -- cycle;
\shade[top color=gray,bottom color=black,clip] (0,0) -- ++ (1.9,0) -- ++ (0,-1.9) -- ++(-0.8,0) to
[out=90,in=-90] ++(-1.1,1.7) -- cycle;
\fill[gray!20!black,opacity=0.3] (1.9,0) rectangle ++ (-2,-2);
\end{scope}
%\translight{shift={(3.6,-1.9)},xscale=-1}
\begin{scope}[shift={(3.6,-1.9)},xscale=-1]
\draw[fill=black!80!gray] (1.9,0.3) -- ++(0.2,0) -- ++(0,-2.4) -- ++(-0.2,0) -- cycle;
\shade[top color=gray,bottom color=black,clip] (0,0) -- ++ (1.9,0) -- ++ (0,-1.9) -- ++(-0.8,0) to
[out=90,in=-90] ++(-1.1,1.7) -- cycle;
\fill[gray!20!black,opacity=0.3] (1.9,0) rectangle ++ (-2,-2);
\end{scope}
%
\shade[ball color=gray!50!black] (1.1,3.6) -- (-1.1,3.6) to[out=90,in=90] cycle;

\end{tikzpicture}
\end{document}

请注意,我生活在不同的时区,因此太阳的位置与图片中的位置略有不同。如果您对此不满意,请查看这个帖子其中解释了如何自定义角度。

更新:为我们的鸭子。灵感来自乌尔里克·菲舍尔鸭子灯。(在编写以下代码时,我已经忘记了 Ulrike 的帖子,但显然我之前见过它。)

\documentclass{article}
\usepackage{animate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[active,tightpage]{preview}
\makeatletter
\def\@anim@@newframe{\@ifstar\@anim@newframe\@anim@newframe}
\def\@anim@newframe{\end{preview}\begin{preview}}
\renewenvironment{animateinline}[2][]{%
  \let\newframe\@anim@@newframe%
  \let\multiframe\@anim@multiframe%
  \begin{preview}}{%
  \end{preview}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\usepackage{tikz}
\usetikzlibrary{shadings}

\newcommand{\translight}[1]{\begin{scope}[#1]
\shade[top color=gray,bottom color=black] (0,0) -- ++ (1.9,0) -- ++ (0,-1.9) -- ++(-0.8,0) to
[out=90,in=-90] ++(-1.1,1.7) -- cycle;
\draw[fill=black!80!gray] (1.9,0.3) -- ++(0.2,0) -- ++(0,-2.4) -- ++(-0.2,0) -- cycle;
\end{scope}
}
\newcommand{\bulbback}[2][]{\begin{scope}[#1]
\draw[thick,fill=black!80!gray] (-1.2,-1.4) coordinate (bl) rectangle ++(2.4,2.2)
coordinate (tr);

\draw[fill=black!97!gray] (bl) -- ++ (-0.12,-0.12) -- ++(2.64,0) -- (bl-|tr) -- cycle;
\draw[fill=black!98!gray] (bl-|tr) -- ++ (0.12,-0.12) -- ++(0,2.44) -- (tr) -- cycle;
\draw[fill=black!50!gray] (tr-|bl) -- ++ (-0.12,0.12) -- ++(2.64,0) -- (tr) -- cycle;
\draw[fill=black!50!gray] (tr-|bl) -- ++ (-0.12,0.12) -- ++(0,-2.44)
-- (bl) -- cycle;

\end{scope}
}
\newcommand{\bulbduck}[2][]{\begin{scope}[#1]
\begin{scope}[xshift=-18,yshift=-21,scale=0.6]% from the tikzducks package
\draw[clip]
  (0.513,1.145) .. controls (0.267, 1.102) and (-0.125,0.657) .. (0.289,0.261)
  (0.289,0.261) .. controls (0.704,-0.135) and ( 2.863,0.130) .. (1.818,1.419)
        -- (1.35,1.20) arc (-30:185:0.50 and 0.625) --(0.406,1.472)
         .. controls (0.269,1.369) and (0.083,0.850) .. (0.600,1.300)
         --(0.513,1.145)
         -- cycle;
\ifcase#2
\shade[ball color=orange!10!red] (1.1,1.2) circle (1.6);
\or
\shade[ball color=orange!50!yellow] (1.1,1.2) circle (1.6);
\or
\shade[ball color=green!70!black] (1.1,1.2) circle (1.6);
\fi
\end{scope}
\end{scope}
}
\def\X{3}
\begin{document}
\begin{animateinline}[autoplay,loop]{2}
\multiframe{4}{i=1+1}{\pgfmathtruncatemacro{\X}{\i-1}
\begin{tikzpicture}
\draw[fill=black!90!gray] (-1.5,-4.3) rectangle (1.5,3.6);
\bulbback[shift={(0,2.4)}]{0}
\bulbback[shift={(0,0)}]{1}
\bulbback[shift={(0,-2.4)}]{2}
\ifcase\X
\bulbduck[shift={(0,2.2)}]{0}
\or
\bulbduck[shift={(0,2.2)}]{0}
\bulbduck[shift={(0,-0.2)}]{1}
\or
\bulbduck[shift={(0,-2.6)}]{2}
\or
\bulbduck[shift={(0,-0.2)}]{1}
\fi
\translight{shift={(-3.6,3.2)}}
\translight{shift={(-3.6,0.7)}}
\translight{shift={(-3.6,-1.9)}}
%\translight{shift={(3.6,3.2)},xscale=-1}
\begin{scope}[shift={(3.6,3.2)},xscale=-1]
\draw[fill=black!80!gray] (1.9,0.3) -- ++(0.2,0) -- ++(0,-2.4) -- ++(-0.2,0) -- cycle;
\shade[top color=gray,bottom color=black,clip] (0,0) -- ++ (1.9,0) -- ++ (0,-1.9) -- ++(-0.8,0) to
[out=90,in=-90] ++(-1.1,1.7) -- cycle;
\fill[gray!20!black,opacity=0.3] (1.9,0) -- ++(-0.2,0) -- ++ (-1.8,-1.8) -- ++ (2,0) -- cycle;
\end{scope}
%\translight{shift={(3.6,0.7)},xscale=-1}
\begin{scope}[shift={(3.6,0.7)},xscale=-1]
\draw[fill=black!80!gray] (1.9,0.3) -- ++(0.2,0) -- ++(0,-2.4) -- ++(-0.2,0) -- cycle;
\shade[top color=gray,bottom color=black,clip] (0,0) -- ++ (1.9,0) -- ++ (0,-1.9) -- ++(-0.8,0) to
[out=90,in=-90] ++(-1.1,1.7) -- cycle;
\fill[gray!20!black,opacity=0.3] (1.9,0) rectangle ++ (-2,-2);
\end{scope}
%\translight{shift={(3.6,-1.9)},xscale=-1}
\begin{scope}[shift={(3.6,-1.9)},xscale=-1]
\draw[fill=black!80!gray] (1.9,0.3) -- ++(0.2,0) -- ++(0,-2.4) -- ++(-0.2,0) -- cycle;
\shade[top color=gray,bottom color=black,clip] (0,0) -- ++ (1.9,0) -- ++ (0,-1.9) -- ++(-0.8,0) to
[out=90,in=-90] ++(-1.1,1.7) -- cycle;
\fill[gray!20!black,opacity=0.3] (1.9,0) rectangle ++ (-2,-2);
\end{scope}
%
\shade[ball color=gray!50!black] (1.1,3.6) -- (-1.1,3.6) to[out=90,in=90] cycle;
%
\end{tikzpicture}
}
\end{animateinline}
\end{document}

在此处输入图片描述

答案2

Z 不擅长 3D。特别是,它不支持照明 - 没有光源、阴影等概念。伪造总是可能的 - 如果你愿意,可以逐个像素地绘画 - 但这是毫无意义的浪费时间。

如果您确实需要自己绘制,请使用专为 3D 设计且能够处理光源的工具。有人提到过 Asymptote,但可能还有更好的选择。如果您将其创建为 2D 图像,Asymptote 很好,但如果您切换到 3D,它会坚持使用光栅输出。

然而,对于这幅图像来说,这种努力实际上是毫无意义的,因为高分辨率的光栅和矢量图已经可以从https://openclipart.org/detail/118837/traffic-light-dan-gerhar-01。下载 PDF 并使用\includegraphics是获得卓越品质的轻松途径。或者,您可以尝试下载 SVG 并进行转换。我最初使用 Inkscape 的尝试并不是很成功,但通过微调可能会做得更好。

Inkscape 输出

作为参考,这是我使用 Inkscape 尝试的结果。我猜想这其中肯定有窍门,但这些留给读者练习。也就是说,我不知道它们是什么——我的转换非常不稳定,不幸的是,失败的次数多于成功的次数。(驴子工作正常;驴子和交通灯则不太好。)

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}
\definecolor{c242424}{RGB}{36,36,36}
\definecolor{c4c4c4c}{RGB}{76,76,76}

\begin{tikzpicture}[y=0.80pt, x=0.80pt, yscale=-1.000000, xscale=1.000000, inner sep=0pt, outer sep=0pt]
\begin{scope}[shift={(-29.144,-25.155)}]
  \begin{scope}[shift={(-97.143,-117.14)}]
    \path[cm={{0.91993,0.0,0.0,1.1621,(18.431,13.418)}},color=black]
      (535.3808,160.3975)arc(-0.000:90.000:100.005100 and
      49.497)arc(90.000:180.000:100.005100 and 49.497)arc(180.000:270.000:100.005100
      and 49.497)arc(270.000:360.000:100.005100 and 49.497) -- cycle;
    \path[color=black,rounded corners=0.0000cm] (300.0000,193.1500) rectangle
      (536.0700,828.7100);
        \path[color=black,fill=c242424,rounded corners=0.0000cm] (317.8600,205.2200)
          rectangle (520.0000,407.3600);
        \path[fill=c4c4c4c,even odd rule] (520.2500,204.9800) -- (318.1400,204.9800) --
          (326.3100,213.1500) -- (512.0900,213.1500) -- (520.2500,204.9800) -- cycle;
        \path[fill=black,even odd rule] (520.2500,407.6000) -- (317.6400,407.6000) --
          (325.8100,399.4300) -- (512.0900,399.4300) -- (520.2500,407.6000) -- cycle;
        \path[fill=black,even odd rule] (317.6400,204.4800) -- (317.6400,407.6000) --
          (325.8100,399.4300) -- (325.8100,212.6400) -- (317.6400,204.4800) -- cycle;
        \path[fill=c4c4c4c,even odd rule] (520.2500,204.9800) -- (520.2500,407.6000) --
          (512.0900,399.4300) -- (512.0900,213.1500) -- (520.2500,204.9800) -- cycle;
      \begin{scope}[shift={(0,-0.2529)}]
        \path[cm={{1.4033,0.0,0.0,1.4033,(-154.44,-176.16)}},color=black]
          (462.8571,343.7907)arc(0.000:90.000:54.286)arc(90.000:180.000:54.286)arc(180.000:270.000:54.286)arc(270.000:360.000:54.286)
          -- cycle;
        \path[cm={{1.4033,0.0,0.0,1.4033,(-154.44,-176.16)}},color=black,draw=black,line
          join=round,line cap=round,line width=4.276pt]
          (462.8571,343.7907)arc(0.000:90.000:54.286)arc(90.000:180.000:54.286)arc(180.000:270.000:54.286)arc(270.000:360.000:54.286)
          -- cycle;
      \end{scope}
      \begin{scope}[shift={(0,205.0)}]
        \path[color=black,fill=c242424,rounded corners=0.0000cm] (317.8600,205.2200)
          rectangle (520.0000,407.3600);
        \path[fill=c4c4c4c,even odd rule] (520.2500,204.9800) -- (318.1400,204.9800) --
          (326.3100,213.1500) -- (512.0900,213.1500) -- (520.2500,204.9800) -- cycle;
        \path[fill=black,even odd rule] (520.2500,407.6000) -- (317.6400,407.6000) --
          (325.8100,399.4300) -- (512.0900,399.4300) -- (520.2500,407.6000) -- cycle;
        \path[fill=black,even odd rule] (317.6400,204.4800) -- (317.6400,407.6000) --
          (325.8100,399.4300) -- (325.8100,212.6400) -- (317.6400,204.4800) -- cycle;
        \path[fill=c4c4c4c,even odd rule] (520.2500,204.9800) -- (520.2500,407.6000) --
          (512.0900,399.4300) -- (512.0900,213.1500) -- (520.2500,204.9800) -- cycle;
      \end{scope}
      \begin{scope}[shift={(0,3.247)}]
        \path[cm={{1.4033,0.0,0.0,1.4033,(-154.44,25.336)}},color=black]
          (462.8571,343.7907)arc(0.000:90.000:54.286)arc(90.000:180.000:54.286)arc(180.000:270.000:54.286)arc(270.000:360.000:54.286)
          -- cycle;
        \path[cm={{1.4033,0.0,0.0,1.4033,(-154.44,25.336)}},color=black,draw=black,line
          join=round,line cap=round,line width=4.276pt]
          (462.8571,343.7907)arc(0.000:90.000:54.286)arc(90.000:180.000:54.286)arc(180.000:270.000:54.286)arc(270.000:360.000:54.286)
          -- cycle;
      \end{scope}
      \begin{scope}[shift={(0,410.0)}]
        \path[color=black,fill=c242424,rounded corners=0.0000cm] (317.8600,205.2200)
          rectangle (520.0000,407.3600);
        \path[fill=c4c4c4c,even odd rule] (520.2500,204.9800) -- (318.1400,204.9800) --
          (326.3100,213.1500) -- (512.0900,213.1500) -- (520.2500,204.9800) -- cycle;
        \path[fill=black,even odd rule] (520.2500,407.6000) -- (317.6400,407.6000) --
          (325.8100,399.4300) -- (512.0900,399.4300) -- (520.2500,407.6000) -- cycle;
        \path[fill=black,even odd rule] (317.6400,204.4800) -- (317.6400,407.6000) --
          (325.8100,399.4300) -- (325.8100,212.6400) -- (317.6400,204.4800) -- cycle;
        \path[fill=c4c4c4c,even odd rule] (520.2500,204.9800) -- (520.2500,407.6000) --
          (512.0900,399.4300) -- (512.0900,213.1500) -- (520.2500,204.9800) -- cycle;
      \end{scope}
      \begin{scope}[shift={(0.01812,4.247)}]
        \path[cm={{1.4033,0.0,0.0,1.4033,(-154.44,229.34)}},color=black]
          (462.8571,343.7907)arc(0.000:90.000:54.286)arc(90.000:180.000:54.286)arc(180.000:270.000:54.286)arc(270.000:360.000:54.286)
          -- cycle;
        \path[cm={{1.4033,0.0,0.0,1.4033,(-154.44,229.34)}},color=black,draw=black,line
          join=round,line cap=round,line width=4.276pt]
          (462.8571,343.7907)arc(0.000:90.000:54.286)arc(90.000:180.000:54.286)arc(180.000:270.000:54.286)arc(270.000:360.000:54.286)
          -- cycle;
      \end{scope}
    \begin{scope}[shift={(14.0,0)}]
      \path[color=black,draw=black,line cap=round,line width=6.000pt]
        (547.2900,790.9300) -- (548.7100,640.2200) -- (692.2900,640.2200) .. controls
        (691.7400,674.7900) and (699.9500,686.2100) .. (646.7800,729.9900) .. controls
        (618.7100,753.1100) and (604.3400,759.5500) .. (603.0000,790.9300) --
        (547.2900,790.9300) -- cycle;
      \path[color=black,fill=c242424,rounded corners=0.0000cm] (522.2900,615.0000)
        rectangle (538.0040,817.5400);
      \path[fill=c4c4c4c,even odd rule] (537.9600,614.9800) -- (537.9600,817.6000) --
        (546.1300,809.4300) -- (546.1300,623.1500) -- (537.9600,614.9800) -- cycle;
    \end{scope}
    \begin{scope}[shift={(14.0,-410.0)}]
      \path[color=black,draw=black,line cap=round,line width=6.000pt]
        (547.2900,790.9300) -- (548.7100,640.2200) -- (692.2900,640.2200) .. controls
        (691.7400,674.7900) and (699.9500,686.2100) .. (646.7800,729.9900) .. controls
        (618.7100,753.1100) and (604.3400,759.5500) .. (603.0000,790.9300) --
        (547.2900,790.9300) -- cycle;
      \path[color=black,fill=c242424,rounded corners=0.0000cm] (522.2900,615.0000)
        rectangle (538.0040,817.5400);
      \path[fill=c4c4c4c,even odd rule] (537.9600,614.9800) -- (537.9600,817.6000) --
        (546.1300,809.4300) -- (546.1300,623.1500) -- (537.9600,614.9800) -- cycle;
\end{scope}
\begin{scope}[shift={(14.0,-205.0)}]
  \path[color=black,draw=black,line cap=round,line width=6.000pt]
    (547.2900,790.9300) -- (548.7100,640.2200) -- (692.2900,640.2200) .. controls
    (691.7400,674.7900) and (699.9500,686.2100) .. (646.7800,729.9900) .. controls
    (618.7100,753.1100) and (604.3400,759.5500) .. (603.0000,790.9300) --
    (547.2900,790.9300) -- cycle;
  \path[color=black,fill=c242424,rounded corners=0.0000cm] (522.2900,615.0000)
    rectangle (538.0040,817.5400);
  \path[fill=c4c4c4c,even odd rule] (537.9600,614.9800) -- (537.9600,817.6000) --
    (546.1300,809.4300) -- (546.1300,623.1500) -- (537.9600,614.9800) -- cycle;
\end{scope}
\begin{scope}[cm={{-1.0,0.0,0.0,1.0,(822.49,0.0)}}]
  \path[color=black,draw=black,line cap=round,line width=6.000pt]
    (547.2900,790.9300) -- (548.7100,640.2200) -- (692.2900,640.2200) .. controls
    (691.7400,674.7900) and (699.9500,686.2100) .. (646.7800,729.9900) .. controls
    (618.7100,753.1100) and (604.3400,759.5500) .. (603.0000,790.9300) --
    (547.2900,790.9300) -- cycle;
  \path[color=black,fill=c242424,rounded corners=0.0000cm] (522.2900,615.0000)
    rectangle (538.0040,817.5400);
  \path[fill=black,even odd rule] (537.9600,614.9800) -- (537.9600,817.6000) --
    (546.1300,809.4300) -- (546.1300,623.1500) -- (537.9600,614.9800) -- cycle;
\end{scope}
\begin{scope}[cm={{-1.0,0.0,0.0,1.0,(822.49,-410.0)}}]
  \path[color=black,draw=black,line cap=round,line width=6.000pt]
    (547.2900,790.9300) -- (548.7100,640.2200) -- (692.2900,640.2200) .. controls
    (691.7400,674.7900) and (699.9500,686.2100) .. (646.7800,729.9900) .. controls
    (618.7100,753.1100) and (604.3400,759.5500) .. (603.0000,790.9300) --
    (547.2900,790.9300) -- cycle;
  \path[color=black,fill=c242424,rounded corners=0.0000cm] (522.2900,615.0000)
    rectangle (538.0040,817.5400);
  \path[fill=black,even odd rule] (537.9600,614.9800) -- (537.9600,817.6000) --
    (546.1300,809.4300) -- (546.1300,623.1500) -- (537.9600,614.9800) -- cycle;
\end{scope}
\begin{scope}[cm={{-1.0,0.0,0.0,1.0,(822.49,-205.0)}}]
  \path[color=black,draw=black,line cap=round,line width=6.000pt]
    (547.2900,790.9300) -- (548.7100,640.2200) -- (692.2900,640.2200) .. controls
    (691.7400,674.7900) and (699.9500,686.2100) .. (646.7800,729.9900) .. controls
    (618.7100,753.1100) and (604.3400,759.5500) .. (603.0000,790.9300) --
    (547.2900,790.9300) -- cycle;
  \path[color=black,fill=c242424,rounded corners=0.0000cm] (522.2900,615.0000)
    rectangle (538.0040,817.5400);
  \path[fill=black,even odd rule] (537.9600,614.9800) -- (537.9600,817.6000) --
    (546.1300,809.4300) -- (546.1300,623.1500) -- (537.9600,614.9800) -- cycle;
\end{scope}
\path[cm={{-1.0,0.0,0.0,1.0,(822.49,-410.0)}},color=black,draw=black,fill=black,opacity=0.250,line
  cap=round,line width=6.000pt] (547.2900,790.9300) -- (548.7100,640.2200) ..
  controls (548.7100,640.2200) and (573.5200,662.6400) .. (646.7800,729.9900) ..
  controls (618.7100,753.1100) and (604.3400,759.5500) .. (603.0000,790.9300) --
  (547.2900,790.9300) -- cycle;
\path[cm={{-1.0,0.0,0.0,1.0,(822.49,-205.0)}},color=black,draw=black,fill=black,opacity=0.250,line
  cap=round,line width=6.000pt] (547.2900,790.9300) -- (548.7100,640.2200) --
  (692.2900,640.2200) .. controls (691.7400,674.7900) and (699.9500,686.2100) ..
  (646.7800,729.9900) .. controls (618.7100,753.1100) and (604.3400,759.5500) ..
  (603.0000,790.9300) -- (547.2900,790.9300) -- cycle;
\path[cm={{-1.0,0.0,0.0,1.0,(822.49,0.0)}},color=black,draw=black,fill=black,opacity=0.250,line
  cap=round,line width=6.000pt] (547.2900,790.9300) -- (548.7100,640.2200) --
  (692.2900,640.2200) .. controls (691.7400,674.7900) and (699.9500,686.2100) ..
  (646.7800,729.9900) .. controls (618.7100,753.1100) and (604.3400,759.5500) ..
  (603.0000,790.9300) -- (547.2900,790.9300) -- cycle;
  \end{scope}
\end{scope}

\end{tikzpicture}
\end{document}

答案3

我建议你应该针对每个目标使用合适的工具,例如蒂克兹专注于节点、文本、箭头、框等,而不是创建2D 图纸虽然只要有技巧和必要的时间就可以完成,但这就像是徒手完成一样因此,您应该选择具有与免费软件相同基本特征的合适工具。因此,我建议使用 Inkscape,您可以在所见即所得的环境中绘图,如您所见,它可以安静地处理在 Tikz 和 Latex 中处理的 pdf 文件,可以获得更好的结果而不会影响质量,但可能会牺牲文件大小。(我希望不会太大)

测试结果改进了在 tikz 中生成的图像,在 inkscape 中修饰,利用 pdf 格式的兼容性,通过导入空白文档添加方程式,该文档中包含在 latex 中制作的方程式(花费任意时间,直到对结果满意为止,就我的情况来说,需要 37 分钟)才能得到这个。

在此处输入图片描述

当然,所有这些图像都是矢量图,您可以随意缩放而不会损失质量。

在此处输入图片描述

成本仅仅​​是文件大小:

  1. Tikz_pdf_文件:tikz2-5D.pdf -->7Kb。
  2. Inkscape SVG 包含导入的 pdf 和已编辑的--> 343Kb。
  3. 导出的 pdf 文件:2-5D.pdf-->25Kb。(这真是太棒了。)
  4. Inkscape SVG 导入方程式 latex pdf 和一些附加版本--> 373Kb。
  5. 导出的 pdf 文件:2-5Dred.pdf-->59Kb。(这个很不错)。

为了检查透明度,我使用了包\background,pdf 文件输出大小为:103Kb。

% arara: pdflatex: {synctex: yes, action: nonstopmode}

\documentclass{scrreprt}
\usepackage{booktabs,caption}
\usepackage{graphicx}
\usepackage[
pages=some,
firstpage=true,
opacity=0.5,
placement=center,
angle=0,
hshift=20,
vshift=10
]{background}
\usepackage{subfigure}
\begin{document}
    \backgroundsetup{contents={\includegraphics[scale=.3]{2-5Dred.pdf}}}

    \begin{figure}[h!]
        \centering
        \subfigure[Obtained exportingTikz to pdf]{\includegraphics[width=.4\textwidth]{tikz2-5D.pdf}} \qquad
        \subfigure[Imported pdf from Tikz in Inkscape and improve effects, and export as pdf]{\includegraphics[width=.4\textwidth]{2-5D.pdf}} \par
        \subfigure[Adding more details and importing random equation generated as a result of the pdf of the empty latex page with normal equation codes, and then including text and a degradation of a dashed line box. Another advantage of using the PDF format is that transparency is available.]{\includegraphics[width=.7\textwidth]{2-5Dred.pdf}}
    \end{figure}

\end{document}

以及在 Inkscape 中导入方程式 pdf 的代码:

% arara: pdflatex: {synctex: yes, action: nonstopmode}

\documentclass{scrreprt}
\usepackage{amsmath,amsfonts,amssymb,latexsym,wasysym}  
\begin{document}
    \pagestyle{empty}
        $\varDelta\phi=\dfrac{4M}{d{s}}+(\dfrac{M}{d{s}})^{2}$
\end{document}

您可以在这里下载文件!

相关内容