如何将“独立”的 TikZ 图像重新置于中心位置以转换为 png

如何将“独立”的 TikZ 图像重新置于中心位置以转换为 png

我正在尝试按照解释的方法构建 png 图标这里。下面是一个示例文件,由于部分边框被吃掉(整个上部和最右边部分的末端),因此需要进行调整。我应该如何修复这个问题?

\documentclass[convert={density=300,size=4600x800,outext=.png}]{standalone}
%\documentclass[a4paper]{article}

\usepackage{tikz}
\usepackage{calc}
\begin{document}
\pagestyle{empty}

% "Nouveau" in green f=23/4

 \noindent\begin{tikzpicture}[x=0.25cm,y=0.25cm]
 % Proportionality constants
  \newcommand*{\jay}{0.25}%
  \newcommand*{\kay}{2}%
 \newcommand*{\hay}{3}%
 \newcommand*{\way}{4}%
  \newcommand*{\bay}{3.5}%
 % Fundamental coordinates of points or vectors
  \newcommand*{\xv}{-0.5*\jay}%
  \newcommand*{\yv}{2*\jay}%
  \newcommand*{\xfive}{0*\jay}%
  \newcommand*{\yfive}{0*\jay}%
  % Deduced coordinates
 \pgfmathsetmacro{\xu}{\bay*\yv}% 
 \pgfmathsetmacro{\yu}{-\bay*\xv}% 
 \pgfmathsetmacro{\xsix}{\xfive+\way*\xu}% 
 \pgfmathsetmacro{\ysix}{\yfive+\way*\yu}% 
 \pgfmathsetmacro{\xten}{\xfive+2*\xv}% 
 \pgfmathsetmacro{\yten}{\yfive+2*\yv}% 
\pgfmathsetmacro{\xeleven}{\xten+\way*\xu}% 
 \pgfmathsetmacro{\yeleven}{\yten+\way*\yu}% 
\pgfmathsetmacro{\xone}{\xsix+\xv}% 
 \pgfmathsetmacro{\yone}{\ysix+\yv}% 
\pgfmathsetmacro{\xtwo}{\xone+\xu}% 
 \pgfmathsetmacro{\ytwo}{\yone+\yu}% 
\pgfmathsetmacro{\xthree}{\xtwo+\kay*\xu}% 
 \pgfmathsetmacro{\ythree}{\ytwo+\kay*\yu}% 
\pgfmathsetmacro{\xtwentytwo}{\xtwo-\hay*\xv}% 
 \pgfmathsetmacro{\ytwentytwo}{\ytwo-\hay*\yv}% 
\pgfmathsetmacro{\xtwentythree}{\xtwentytwo+\kay*\xu}% 
 \pgfmathsetmacro{\ytwentythree}{\ytwentytwo+\kay*\yu}% 
\pgfmathsetmacro{\xseventeen}{\xtwentytwo-\xv}% 
 \pgfmathsetmacro{\yseventeen}{\ytwentytwo-\yv}% 
 \pgfmathsetmacro{\xeighteen}{\xseventeen+\kay*\xu}% 
 \pgfmathsetmacro{\yeighteen}{\yseventeen+\kay*\yu}% 
 \pgfmathsetmacro{\xseven}{\xtwo+\hay*\xv}% 
 \pgfmathsetmacro{\yseven}{\ytwo+\hay*\yv}% 
 \pgfmathsetmacro{\xeight}{\xseven+\kay*\xu}% 
 \pgfmathsetmacro{\yeight}{\yseven+\kay*\yu}% 
 \pgfmathsetmacro{\xtwelve}{\xseven+\xv}% 
 \pgfmathsetmacro{\ytwelve}{\yseven+\yv}% 
  \pgfmathsetmacro{\xthirteen}{\xtwelve+\kay*\xu}% 
 \pgfmathsetmacro{\ythirteen}{\ytwelve+\kay*\yu}% 
 \pgfmathsetmacro{\xfour}{\xthree+\hay*\yv}% 
 \pgfmathsetmacro{\yfour}{\ythree-\hay*\xv}% 
 \pgfmathsetmacro{\xnine}{\xfour+\yv}% 
 \pgfmathsetmacro{\ynine}{\yfour-\xv}% 
 \pgfmathsetmacro{\xfourteen}{\xfive+\xv-\yv}% 
 \pgfmathsetmacro{\yfourteen}{\yfive+\xv+\yv}% 
  \coordinate (A1) at (\xone,\yone);
  \coordinate (A2) at (\xtwo,\ytwo);
  \coordinate (A3) at (\xthree,\ythree);
  \coordinate (A4) at (\xfour,\yfour);
  \coordinate (A5) at (\xfive,\yfive);
  \coordinate (A6) at (\xsix,\ysix);  
  \coordinate (A7) at (\xseven,\yseven);
  \coordinate (A8) at (\xeight,\yeight);  
  \coordinate (A9) at (\xnine,\ynine);   
  \coordinate (A10) at (\xten,\yten);    
\coordinate (A11) at (\xeleven,\yeleven);    
\coordinate (A12) at (\xtwelve,\ytwelve);    
\coordinate (A13) at (\xthirteen,\ythirteen);    
\coordinate (A14) at (\xfourteen,\yfourteen);    
\coordinate (A17) at (\xseventeen,\yseventeen);   
\coordinate (A18) at (\xeighteen,\yeighteen);   
\coordinate (A22) at (\xtwentytwo,\ytwentytwo);  
\coordinate (A23) at (\xtwentythree,\ytwentythree);    
  \fill[fill=green] (A14) -- (A5) -- (A6) -- (A11) -- (A10) -- cycle;
  \fill[fill=green] (A6) -- (A17) -- (A22) -- (A1) -- cycle;
  \fill[fill=green] (A17) -- (A18) -- (A23) -- (A22) -- cycle;
 \fill[fill=green] (A7) -- (A8) -- (A13) -- (A12) -- cycle;
 %\draw (A23) -- (A4) -- (A8);
% \draw (A23) .. controls (A14) .. (A4);
 \pgfmathsetmacro{\dee}{\hay*(veclen(\xv,\yv))}% 
 \pgfmathsetmacro{\deetwo}{(\hay+1)*(veclen(\xv,\yv))}% 
 \pgfmathsetmacro{\anglestart}{atan2(\xtwentythree-\xthree,\ytwentythree-\ythree)}%
 \pgfmathsetmacro{\angletarget}{atan2(\xeight-\xthree,\yeight-\ythree)}%
 \fill[fill=green]  (A23) arc (\anglestart:\angletarget:\dee) -- (A13) arc (\angletarget:\anglestart:\deetwo) -- (A23);
 %\draw[step=0.1cm,gray] (-1,0) grid (15,6);
  %\draw [step=1cm] (-1,0) grid (15,6);
\coordinate (C1) at (3.4,5);
\coordinate (C2) at (4,4);
\coordinate (C3) at (5,3.6);    
\coordinate (C4) at (6,4.5);    
\coordinate (C5) at (7,4.7);
\coordinate (C6) at (8,4);
\coordinate (C7) at (8.6,3);
\coordinate (C25) at (9,2.7);    
\coordinate (C8) at (10,2.4);    
\coordinate (C9) at (11,2.8);
\coordinate (C10) at (11.5,2);    
\coordinate (C11) at (12,1);
\coordinate (C12) at (12.4,0.3);   
\coordinate (C13) at (12.6,0.3);    
\coordinate (C14) at (12.2,1);    
\coordinate (C15) at (11.7,2);
\coordinate (C16) at (11,3.1);    
\coordinate (C17) at (10,2.6);
\coordinate (C18) at (9,2.9);    
\coordinate (C26) at (8.2,4);
\coordinate (C19) at (8,4.3);
\coordinate (C20) at (7,4.9);    
\coordinate (C21) at (6,4.7);
\coordinate (C22) at (5,3.8);   
\coordinate (C23) at (4,4.2);    
\coordinate (C24) at (3.6,5);   
\filldraw plot [smooth cycle] coordinates { (C1)  (C2)  (C3) (C4) (C5) (C6) (C7) (C25) (C8) (C9) (C10)  
(C11) (C12) (C13) (C14) (C15) (C16) (C17) (C18) (C26) (C19) (C20) (C21) (C22) (C23) (C24)};
 \fill[fill=green] (A1) -- (A7) -- (A12) -- (A11) -- cycle;
% \draw [step=0.1cm] (-28,-4) grid (16,12);
%\draw [step=1cm] (-28,-4) grid (16,12);
% \draw (0,0) node {$\bullet$};
 \draw (A5)++(-20,2.5) node[scale=3] {\sf\Huge\textcolor{green}{nouveau}};
  \newcommand*{\xzed}{-140*\jay}%
  \newcommand*{\yzed}{-10*\jay}%
  \newcommand*{\xzedtwo}{50*\jay}%
  \newcommand*{\dusttwo}{20*\jay}%
 \coordinate (Z1) at (\xzed,\yzed);
 \coordinate (Z2) at (\xzedtwo,\yzed);
 \coordinate (Z3) at (\xzedtwo,\yzed+2*\dusttwo);
 \coordinate (Z4) at (\xzed,\yzed+2*\dusttwo);  
 \draw (Z1)  -- (Z2) arc(-90:90:\dusttwo) (Z3) -- (Z4) arc(90:270:\dusttwo) (Z1) ;
\end{tikzpicture}



\end{document}

答案1

你想要这样的东西吗?

在此处输入图片描述

代码中的主要问题在最后一行

\draw (Z1)  -- (Z2) arc(-90:90:\dusttwo) (Z3) -- (Z4) arc(90:270:\dusttwo) (Z1) ;

半径\dusttwo太短,而不是20*\jay我使用的22*\jay(根据您的喜好进行调整)。您的命令绘制了两条路径,(Z1) -- (Z2) arc(-90:90:\dusttwo)后面跟着(Z3) -- (Z4) arc(90:270:\dusttwo) (Z1)。没有理由进行这样的划分,一条路径就足够了:

 \draw (Z1)  -- (Z2) arc(-90:90:22*\jay) coordinate (aux) -- (aux-|Z1) arc(90:270:22*\jay);

其他一些评论:

对于我来说,该代码无需\usepackage{calc}(不要将其与混淆\usetikzlibrary{calc},这既不是也没有必要)就可以工作。

如果您使用standalone类来进行隔离,tikzpicture则没有必要\pagestyle{empty},并且\noindent这会在最终结果中引入一点转变。

而且,如果你需要,你还可以引入一个border=...选项,在standalone剪辑结果之前会考虑该选项。我在这里没有用过,这只是信息。

\documentclass[convert={density=300,size=4600x800,outext=.png}]{standalone}
%\documentclass[a4paper]{article}

\usepackage{tikz}
%\usepackage{calc}
\begin{document}
\begin{tikzpicture}[x=0.25cm,y=0.25cm]
 % Proportionality constants
  \newcommand*{\jay}{0.25}%
  \newcommand*{\kay}{2}%
 \newcommand*{\hay}{3}%
 \newcommand*{\way}{4}%
  \newcommand*{\bay}{3.5}%
 % Fundamental coordinates of points or vectors
  \newcommand*{\xv}{-0.5*\jay}%
  \newcommand*{\yv}{2*\jay}%
  \newcommand*{\xfive}{0*\jay}%
  \newcommand*{\yfive}{0*\jay}%
  % Deduced coordinates
 \pgfmathsetmacro{\xu}{\bay*\yv}% 
 \pgfmathsetmacro{\yu}{-\bay*\xv}% 
 \pgfmathsetmacro{\xsix}{\xfive+\way*\xu}% 
 \pgfmathsetmacro{\ysix}{\yfive+\way*\yu}% 
 \pgfmathsetmacro{\xten}{\xfive+2*\xv}% 
 \pgfmathsetmacro{\yten}{\yfive+2*\yv}% 
\pgfmathsetmacro{\xeleven}{\xten+\way*\xu}% 
 \pgfmathsetmacro{\yeleven}{\yten+\way*\yu}% 
\pgfmathsetmacro{\xone}{\xsix+\xv}% 
 \pgfmathsetmacro{\yone}{\ysix+\yv}% 
\pgfmathsetmacro{\xtwo}{\xone+\xu}% 
 \pgfmathsetmacro{\ytwo}{\yone+\yu}% 
\pgfmathsetmacro{\xthree}{\xtwo+\kay*\xu}% 
 \pgfmathsetmacro{\ythree}{\ytwo+\kay*\yu}% 
\pgfmathsetmacro{\xtwentytwo}{\xtwo-\hay*\xv}% 
 \pgfmathsetmacro{\ytwentytwo}{\ytwo-\hay*\yv}% 
\pgfmathsetmacro{\xtwentythree}{\xtwentytwo+\kay*\xu}% 
 \pgfmathsetmacro{\ytwentythree}{\ytwentytwo+\kay*\yu}% 
\pgfmathsetmacro{\xseventeen}{\xtwentytwo-\xv}% 
 \pgfmathsetmacro{\yseventeen}{\ytwentytwo-\yv}% 
 \pgfmathsetmacro{\xeighteen}{\xseventeen+\kay*\xu}% 
 \pgfmathsetmacro{\yeighteen}{\yseventeen+\kay*\yu}% 
 \pgfmathsetmacro{\xseven}{\xtwo+\hay*\xv}% 
 \pgfmathsetmacro{\yseven}{\ytwo+\hay*\yv}% 
 \pgfmathsetmacro{\xeight}{\xseven+\kay*\xu}% 
 \pgfmathsetmacro{\yeight}{\yseven+\kay*\yu}% 
 \pgfmathsetmacro{\xtwelve}{\xseven+\xv}% 
 \pgfmathsetmacro{\ytwelve}{\yseven+\yv}% 
  \pgfmathsetmacro{\xthirteen}{\xtwelve+\kay*\xu}% 
 \pgfmathsetmacro{\ythirteen}{\ytwelve+\kay*\yu}% 
 \pgfmathsetmacro{\xfour}{\xthree+\hay*\yv}% 
 \pgfmathsetmacro{\yfour}{\ythree-\hay*\xv}% 
 \pgfmathsetmacro{\xnine}{\xfour+\yv}% 
 \pgfmathsetmacro{\ynine}{\yfour-\xv}% 
 \pgfmathsetmacro{\xfourteen}{\xfive+\xv-\yv}% 
 \pgfmathsetmacro{\yfourteen}{\yfive+\xv+\yv}% 
  \coordinate (A1) at (\xone,\yone);
  \coordinate (A2) at (\xtwo,\ytwo);
  \coordinate (A3) at (\xthree,\ythree);
  \coordinate (A4) at (\xfour,\yfour);
  \coordinate (A5) at (\xfive,\yfive);
  \coordinate (A6) at (\xsix,\ysix);  
  \coordinate (A7) at (\xseven,\yseven);
  \coordinate (A8) at (\xeight,\yeight);  
  \coordinate (A9) at (\xnine,\ynine);   
  \coordinate (A10) at (\xten,\yten);    
\coordinate (A11) at (\xeleven,\yeleven);    
\coordinate (A12) at (\xtwelve,\ytwelve);    
\coordinate (A13) at (\xthirteen,\ythirteen);    
\coordinate (A14) at (\xfourteen,\yfourteen);    
\coordinate (A17) at (\xseventeen,\yseventeen);   
\coordinate (A18) at (\xeighteen,\yeighteen);   
\coordinate (A22) at (\xtwentytwo,\ytwentytwo);  
\coordinate (A23) at (\xtwentythree,\ytwentythree);    
  \fill[fill=green] (A14) -- (A5) -- (A6) -- (A11) -- (A10) -- cycle;
  \fill[fill=green] (A6) -- (A17) -- (A22) -- (A1) -- cycle;
  \fill[fill=green] (A17) -- (A18) -- (A23) -- (A22) -- cycle;
 \fill[fill=green] (A7) -- (A8) -- (A13) -- (A12) -- cycle;
 %\draw (A23) -- (A4) -- (A8);
% \draw (A23) .. controls (A14) .. (A4);
 \pgfmathsetmacro{\dee}{\hay*(veclen(\xv,\yv))}% 
 \pgfmathsetmacro{\deetwo}{(\hay+1)*(veclen(\xv,\yv))}% 
 \pgfmathsetmacro{\anglestart}{atan2(\xtwentythree-\xthree,\ytwentythree-\ythree)}%
 \pgfmathsetmacro{\angletarget}{atan2(\xeight-\xthree,\yeight-\ythree)}%
 \fill[fill=green]  (A23) arc (\anglestart:\angletarget:\dee) -- (A13) arc (\angletarget:\anglestart:\deetwo) -- (A23);
 %\draw[step=0.1cm,gray] (-1,0) grid (15,6);
  %\draw [step=1cm] (-1,0) grid (15,6);
\coordinate (C1) at (3.4,5);
\coordinate (C2) at (4,4);
\coordinate (C3) at (5,3.6);    
\coordinate (C4) at (6,4.5);    
\coordinate (C5) at (7,4.7);
\coordinate (C6) at (8,4);
\coordinate (C7) at (8.6,3);
\coordinate (C25) at (9,2.7);    
\coordinate (C8) at (10,2.4);    
\coordinate (C9) at (11,2.8);
\coordinate (C10) at (11.5,2);    
\coordinate (C11) at (12,1);
\coordinate (C12) at (12.4,0.3);   
\coordinate (C13) at (12.6,0.3);    
\coordinate (C14) at (12.2,1);    
\coordinate (C15) at (11.7,2);
\coordinate (C16) at (11,3.1);    
\coordinate (C17) at (10,2.6);
\coordinate (C18) at (9,2.9);    
\coordinate (C26) at (8.2,4);
\coordinate (C19) at (8,4.3);
\coordinate (C20) at (7,4.9);    
\coordinate (C21) at (6,4.7);
\coordinate (C22) at (5,3.8);   
\coordinate (C23) at (4,4.2);    
\coordinate (C24) at (3.6,5);   
\filldraw plot [smooth cycle] coordinates { (C1)  (C2)  (C3) (C4) (C5) (C6) (C7) (C25) (C8) (C9) (C10)  
(C11) (C12) (C13) (C14) (C15) (C16) (C17) (C18) (C26) (C19) (C20) (C21) (C22) (C23) (C24)};
 \fill[fill=green] (A1) -- (A7) -- (A12) -- (A11) -- cycle;
% \draw [step=0.1cm] (-28,-4) grid (16,12);
%\draw [step=1cm] (-28,-4) grid (16,12);
% \draw (0,0) node {$\bullet$};
 \draw (A5)++(-20,2.5) node[scale=3] {\sf\Huge\textcolor{green}{nouveau}};
  \newcommand*{\xzed}{-140*\jay}%
  \newcommand*{\yzed}{-10*\jay}%
  \newcommand*{\xzedtwo}{50*\jay}%
  \newcommand*{\dusttwo}{20*\jay}%
 \coordinate (Z1) at (\xzed,\yzed);
 \coordinate (Z2) at (\xzedtwo,\yzed);
 \coordinate (Z3) at (\xzedtwo,\yzed+2*\dusttwo);
 \coordinate (Z4) at (\xzed,\yzed+2*\dusttwo);  
% \draw (Z1)  -- (Z2) arc(-90:90:\dusttwo) (Z3) -- (Z4) arc(90:270:\dusttwo) (Z1) ;
 \draw (Z1)  -- (Z2) arc(-90:90:22*\jay) coordinate (aux) -- (aux-|Z1) arc(90:270:22*\jay);
\end{tikzpicture}
\end{document}

相关内容