Tikz 独立版边框不起作用

Tikz 独立版边框不起作用

我目前正在开发一个LFSR 绘图库latex 是从 Python 代码输出的。剩下的一个主要问题是边框。

\documentclass[convert={density=300,size=1080x800,outext=.png},tikz, border={15mm 15mm 15mm 15mm}]{standalone}
\usepackage{xcolor}
\usetikzlibrary{arrows.meta,backgrounds}
\tikzset{{white background/.style={{show background rectangle,tight background,background rectangle/.style={{fill=white}} }} }}

\begin{document}
\begin{tikzpicture}[white background]


%node 5
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (25, 20) {};
    \draw [line width=0.1cm](25,22.0) -- (25,24.0);
    \draw [line width=0.12cm] (25,25.0) circle (1);
    \draw [line width=0.12cm](25,24.0) -- (25,26.0);
    \draw [line width=0.12cm](24,25.0) -- (26,25.0);
    \draw [arrows={-Triangle[angle=90:0.5cm,black,fill=black,line width=0.1cm]}](26,25.0) -- (25.9999,25.0);
%node 4
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (29, 20) {};
%node 3
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (33, 20) {};
%node 2
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (37, 20) {};
    \draw [line width=0.1cm](37,22.0) -- (37,24.0);
    \draw [line width=0.12cm] (37,25.0) circle (1);
    \draw [line width=0.12cm](37,24.0) -- (37,26.0);
    \draw [line width=0.12cm](36,25.0) -- (38,25.0);
    \draw [arrows={-Triangle[angle=90:0.5cm,black,fill=black,line width=0.1cm]}](38,25.0) -- (37.9999,25.0);
%node 1
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (41, 20) {};
%node 0
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (45, 20) {};
    \draw [line width=0.1cm](45,22.0) -- (45,25.0);
\draw[->,line width=0.1cm,arrows={-Triangle[angle=90:0.5cm,black,fill=black,line width=0.1cm]}] (45,25.0) -- (17,25.0) -- (17,20) -- (23.0,20);
\draw[->,line width=0.1cm,arrows={-Triangle[angle=90:0.5cm,black,fill=black,line width=0.1cm]},font=\fontsize{100}{100}\selectfont] (47.0,20) -- (53,20) node[midway,above]{};

\end{tikzpicture}
\end{document}

输出的 PNG 是

在此处输入图片描述

border 参数不起作用,或者至少我不知道如何正确使用它。我见过一个问题,解决方案对我不起作用。

我怎样才能在绘图中做出边框?

答案1

这将在 tikzpicture 内添加一个 15mm 的边框(在代码末尾)。

\documentclass[convert={density=300,size=1080x800,outext=.png},tikz]{standalone}
\usepackage{xcolor}
\usetikzlibrary{arrows.meta,backgrounds}
\tikzset{{white background/.style={{show background rectangle,tight background,background rectangle/.style={{fill=lightgray}} }} }}

\begin{document}
\begin{tikzpicture}[white background]


%node 5
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (25, 20) {};
    \draw [line width=0.1cm](25,22.0) -- (25,24.0);
    \draw [line width=0.12cm] (25,25.0) circle (1);
    \draw [line width=0.12cm](25,24.0) -- (25,26.0);
    \draw [line width=0.12cm](24,25.0) -- (26,25.0);
    \draw [arrows={-Triangle[angle=90:0.5cm,black,fill=black,line width=0.1cm]}](26,25.0) -- (25.9999,25.0);
%node 4
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (29, 20) {};
%node 3
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (33, 20) {};
%node 2
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (37, 20) {};
    \draw [line width=0.1cm](37,22.0) -- (37,24.0);
    \draw [line width=0.12cm] (37,25.0) circle (1);
    \draw [line width=0.12cm](37,24.0) -- (37,26.0);
    \draw [line width=0.12cm](36,25.0) -- (38,25.0);
    \draw [arrows={-Triangle[angle=90:0.5cm,black,fill=black,line width=0.1cm]}](38,25.0) -- (37.9999,25.0);
%node 1
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (41, 20) {};
%node 0
    \draw node[draw, fill={{rgb:black,1;white,5}}, minimum size=4cm,line width=0.1cm,font=\fontsize{100}{100}\selectfont] at (45, 20) {};
    \draw [line width=0.1cm](45,22.0) -- (45,25.0);
\draw[->,line width=0.1cm,arrows={-Triangle[angle=90:0.5cm,black,fill=black,line width=0.1cm]}] (45,25.0) -- (17,25.0) -- (17,20) -- (23.0,20);
\draw[->,line width=0.1cm,arrows={-Triangle[angle=90:0.5cm,black,fill=black,line width=0.1cm]},font=\fontsize{100}{100}\selectfont] (47.0,20) -- (53,20) node[midway,above]{};

\path (current bounding box.north east) +(15mm,15mm) (current bounding box.south west) +(-15mm,-15mm);
\end{tikzpicture}
\end{document}

结果:

在此处输入图片描述

答案2

它确实有效。您的图片有边框,但它是透明的。您可以通过在其他选项卡中打开图片或检查 pdf 文件来检查它。

如果您想用特定颜色填充透明度,则必须删除 alpha 通道(您可以通过传递选项backgroundflatten转换命令来实现):

\documentclass[convert={command=\unexpanded{{convert -density 300 \infile\space -resize 1080x800 -background red -flatten \outfile}},outext=.png,},tikz, border={15mm 15mm 15mm 15mm}]{standalone}
\usepackage{xcolor}
\usetikzlibrary{arrows.meta,backgrounds}
\tikzset{{white background/.style={{show background rectangle,tight background,background rectangle/.style={{fill=yellow}} }} }}

\begin{document}
\begin{tikzpicture}[white background]

...

\end{tikzpicture}
\end{document}

在此处输入图片描述

red在第一行中用你喜欢的颜色进行更改。

相关内容