我在我的文档中插入了 TIZ 环境 - 一切正常,没有错误!只是一个警告,环境尚未打开/关闭:
这是我的代码:
\begin{figure}[H]
\centering
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1, scale=0.7, every node/.style={scale=0.7}]
\draw [fill={rgb, 255:red, 155; green, 155; blue, 155 } ,fill opacity=0.45 ][line width=2.25] (147,92) -- (356,92) -- (356,186.35) -- (147,186.35) -- cycle ;
%Right Arrow [id:dp008081388677440904]
\draw [fill={rgb, 255:red, 248; green, 231; blue, 28 } ,fill opacity=1 ][line width=1.5] (199,14) -- (199,56) -- (209,56) -- (189,84) -- (169,56) -- (179,56) -- (179,14) -- cycle ;
%Right Arrow [id:dp584717372432416]
\draw [fill={rgb, 255:red, 248; green, 231; blue, 28 } ,fill opacity=1 ][line width=1.5] (315,14) -- (315,56) -- (325,56) -- (305,84) -- (285,56) -- (295,56) -- (295,14) -- cycle ;
%Right Arrow [id:dp8933598607947869]
\draw [fill={rgb, 255:red, 184; green, 233; blue, 134 } ,fill opacity=1 ][line width=1.5] (70,130) -- (112,130) -- (112,120) -- (140,140) -- (112,160) -- (112,150) -- (70,150) -- cycle ;
%Right Arrow [id:dp43249460780861937]
\draw [fill={rgb, 255:red, 184; green, 233; blue, 134 } ,fill opacity=1 ][line width=1.5] (363,129) -- (405,129) -- (405,119) -- (433,139) -- (405,159) -- (405,149) -- (363,149) -- cycle ;
%Shape: Rectangle [id:dp02676070817238141]
\draw [line width=3.75] (5.68,-39.65) -- (514.68,-39.65) -- (514.68,210.35) -- (5.68,210.35) -- cycle ;
% Text Node
\draw (156,-24) node [anchor=north west][inner sep=0.75pt] [font=\normalsize] [align=left] {{\scriptsize \textbf{Steuergrößen }}};
% Text Node
\draw (278,-24) node [anchor=north west][inner sep=0.75pt] [align=left] {{\scriptsize \textbf{Störgrößen}}};
% Text Node
\draw (266,224.4) node [anchor=north west][inner sep=0.75pt] {$$};
% Text Node
\draw (151,-6.6) node [anchor=north west][inner sep=0.75pt] [font=\scriptsize] {$\{x_{1} ,\ x_{2} ,\ ...,\ x_{n}\}$};
% Text Node
\draw (267,-6.6) node [anchor=north west][inner sep=0.75pt] [font=\scriptsize] {$\{v_{1} ,\ v_{2} ,\ ...,\ v_{n}\}$};
% Text Node
\draw (439,127) node [anchor=north west][inner sep=0.75pt] [font=\scriptsize] [align=left] {\textbf{Zielgrößen}};
% Text Node
\draw (439,137.4) node [anchor=north west][inner sep=0.75pt] [font=\scriptsize] {$y_{1} ,\ y_{2} ,\ ...,\ y_{3}$};
% Text Node
\draw (13,136) node [anchor=north west][inner sep=0.75pt] [font=\scriptsize] [align=left] {\textbf{Eingaben}};
% Text Node
\draw (177,129) node [anchor=north west][inner sep=0.75pt] [font=\scriptsize] [align=left] {\begin{minipage}[lt]{108.95844000000001pt}\setlength\topsep{0pt}
\begin{center}
\textbf{Versuchsraum}\\\textbf{Ursache-/Wirkunsbez.}
\end{center}
\end{minipage}};
\end{tikzpicture}
\caption{Usache-/Wirkungsbeziehungen als Black-Box-Modell}
\end{figure}
这导致我的整个 Tikz 环境后的格式发生变化并保持与环境中的格式相同,这非常烦人......
如果有人能提供帮助来解决这个问题,那就太好了……
BR,麦克风
答案1
大部分题外话:
- 如果我将您的代码片段插入简单文档容器中:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{figure}[ht]
\centering
% tikzpicture code
\end{figure}
\end{document}
它编译时没有任何错误或警告,并且环境的突出显示也是正确的(至少在 WinEdt 中)
- 但是,代码中很容易出现一些难以发现的错误,因此我建议考虑以表单形式重写代码,使用一些 TikZ 库并定义图像元素的样式。例如,正如您在下面的 MWE 中看到的那样:
\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{fit,
shapes.arrows}
%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[
A/.style args= {#1/#2}{rotate=#1, % for arrows
fill=#2, draw,
single arrow, single arrow head extend=2mm,
minimum height=9mm, minimum width=7mm,
anchor=east},
A/.default = -90/yellow, % setings default arrows arguments
box/.style = {draw, line width=1mm, % for inner box
font=\bfseries\small,
text width=11em, align=flush center, inner sep=1em},
FIT/.style = {draw, line width=2mm, % for outer box
inner sep=2ex, fit=#1},
every label/.append style = {font=\footnotesize\bfseries, inner sep=2pt,
align=center}
]
% inner box
\node (n1) [box] {Versuchsraum Ursache/Wirkunsbez.};
% arrows on the top
\node[A,label={[name=L1]left:Steuergrößen\\
${x_1,x_2,\dotsc,x_n}$}] at ([xshift=-4em] n1.north) {};
\node[A,label={[name=L2]left:Störgrößen\\
${v_1,v_2,\dotsc,v_n}$}] at ([xshift=+4em] n1.north) {};
% arrow on the left
\node[A=0/green,
label={[name=L3]left:Eingaben}] at (n1.west) {};
% arrow on the right
\node[A=180/green,
label={[name=L4]left:Zielgrößen\\
${y_1,y_2,\dotsc,y_n}$}] at (n1.east) {};
% outer box
\node[FIT=(n1) (L1) (L3) (L4)] {};
\end{tikzpicture}
\end{figure}
\begin{figure}[ht]
\centering
\begin{tikzpicture}[
A/.style args= {#1/#2}{rotate=#1, % for arrows
fill=#2, draw,
single arrow, single arrow head extend=2mm,
minimum height=9mm, minimum width=7mm,
anchor=east},
A/.default = -90/yellow, % setings default arrows arguments
box/.style = {draw, line width=1mm, % for inner box
font=\bfseries\small,
text width=7em, align=flush center, inner sep=1ex},
FIT/.style = {draw, line width=2mm, % for outer box
inner sep=2ex, fit=#1},
every label/.append style = {font=\footnotesize\bfseries, inner sep=2pt,
align=center}
]
% inner box
\node (n1) [box] {Versuchsraum Ursache/ Wirkunsbez.};
% arrows on the top
\node[A,label={[name=L1]left:Steuergrößen\\
${x_1,x_2,\dotsc,x_n}$}] at ([xshift=-3em] n1.north) {};
\node[A,label={[name=L2]left:Störgrößen\\
${v_1,v_2,\dotsc,v_n}$}] at ([xshift=+3em] n1.north) {};
% arrow on the left
\node[A=0/green,
label={[name=L3]left:Eingaben}] at (n1.west) {};
% arrow on the right
\node[A=180/green,
label={[name=L4]left:Zielgrößen\\
${y_1,y_2,\dotsc,y_n}$}] at (n1.east) {};
% outer box
\node[FIT=(n1) (L1) (L3) (L4)] {};
\end{tikzpicture}
\end{figure}
\end{document}
其生产成果为:
(红线表示文本边框)
如果将建议的图像代码与您的代码进行比较,您会发现每张图像的代码都更短、结构更好,因此更清晰(至少在我看来)并且不容易出错。
除了这些优点之外,它们还有一个缺点:由于使用相对坐标和命名坐标,因此无法使用scale=...
选项进行缩放tikzpicture
。如果您需要更窄的图像,则需要更改box
内框上方箭头的样式和位置,如第二幅图像的代码中所做的那样。