我现在正在制作图表。我想将节点 A 置于中间,并保持其他节点不变。但是,这两个都不起作用\begin{center}...\end{center}
。\centering
有什么办法可以解决这个问题吗?非常感谢。
\documentclass{article}
%-----------------------------------------------
\usepackage{pdflscape}
%\usepackage{rotating}
\usepackage{adjustbox}
%\usepackage[pdftex]{graphics}
\usepackage[a4paper,margin=0mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{chains, positioning}
\tikzstyle{startstop} = [rectangle, minimum width=3cm, minimum height=1.5cm,text centered, text width=3cm, draw=black]
\tikzstyle{process} = [rectangle, minimum width=2.5cm, minimum height=1cm, text centered, draw=black, fill=orange!0]
\tikzstyle{process2} = [rectangle, minimum width=2.5cm, minimum height=1cm, text centered, draw=black, fill=orange!0]
\tikzstyle{process3} = [rectangle, minimum width=2.5cm, minimum height=1cm, text centered, text width=2.5cm, draw=black, fill=orange!0]
\tikzstyle{process4} = [rectangle, rounded corners, minimum width=2.5cm, minimum height=1cm, text centered, text width=2.5cm, draw=black, fill=orange!0]
\tikzstyle{process5} = [rectangle, rounded corners, minimum width=2.5cm, minimum height=1cm, text centered, text width=2.5cm, draw=black, fill=orange!0]
\tikzstyle{process6} = [rectangle, rounded corners, minimum width=2.5cm, minimum height=1cm, text centered, text width=2.5cm, draw=black, fill=orange!0]
\tikzstyle{process7} = [rectangle, rounded corners, minimum width=2cm, minimum height=1.0cm, text centered, text width=2cm, draw=black, fill=orange!0]
\tikzstyle{process8} = [rectangle, rounded corners, minimum width=1cm, minimum height=1.0cm, text centered, text width=1cm, draw=black, fill=orange!0]
\tikzstyle{arrow} = [thick,->,>=stealth]
%-----------------------------------------------
\begin{document}
\begin{landscape}
\begin{figure}[htb]
\centering
\begin{adjustbox}{width=29.5cm, height=\textheight, keepaspectratio}
\begin{tikzpicture}[node distance=2cm][scale=0.01,anchor=center]
\node (start) [startstop] {\textbf{A}};
\node (pro1) [process, below of=start, yshift=-1cm]{B};
\node (pro2) [process2, right of=pro1, xshift=2.5cm]{C};
\node (pro3) [process3, right of=pro2, xshift=3cm]{D};
\node (pro4) [process4, below of=pro1, yshift=-1cm]{E};
\node (pro5) [process5, right of=pro4, xshift=1cm]{F};
\node (pro6) [process6, right of=pro5, xshift=1cm]{G};
\node (pro7) [process7, right of=pro6, xshift=0.8cm]{H};
\node (pro8) [process8, right of=pro7, xshift=0.08cm]{I};
\draw [arrow] (start) -- (pro1.north);
\draw [arrow] (start) -- (pro2.north);
\draw [arrow] (start) -- (pro3.north);
\draw [arrow] (pro2) -- (pro4.north);
\draw [arrow] (pro2) -- (pro5.north);
\draw [arrow] (pro2) -- (pro6.north);
\draw [arrow] (pro2) -- (pro7.north);
\draw [arrow] (pro2) -- (pro8.north);
\end{tikzpicture}
\end{adjustbox}
\caption{Hello}
\end{figure}
\end{landscape}
\end{document}
答案1
您的原始代码显示:
\node (start) [startstop] {\textbf{A}};
\node (pro1) [process, below of=start, yshift=-1cm]{B};
这意味着将节点放置pro1
在节点 下方start
。因此,它B
是 下方A
而不是C
。如果要将其放置C
在 下方A
,然后放置B
在 左侧C
和D
右侧。
顺便说一句,您正在加载positioning
库,但使用已弃用的语法below of = ...
而不是新的语法below = of ...
。
请阅读PGF/TikZ 中“right of=”和“right=of”之间的区别
我用新的替换了旧的,结果如下:
\documentclass{article}
%-----------------------------------------------
\usepackage{pdflscape}
%\usepackage{rotating}
\usepackage{adjustbox}
%\usepackage[pdftex]{graphics}
\usepackage[a4paper,margin=0mm]{geometry}
\usepackage{tikz}
\usetikzlibrary{chains, positioning}
\tikzstyle{startstop} = [rectangle, minimum width=3cm, minimum height=1.5cm,text centered, text width=3cm, draw=black]
\tikzstyle{process} = [rectangle, minimum width=2.5cm, minimum height=1cm, text centered, draw=black, fill=orange!0]
\tikzstyle{process2} = [rectangle, minimum width=2.5cm, minimum height=1cm, text centered, draw=black, fill=orange!0]
\tikzstyle{process3} = [rectangle, minimum width=2.5cm, minimum height=1cm, text centered, text width=2.5cm, draw=black, fill=orange!0]
\tikzstyle{process4} = [rectangle, rounded corners, minimum width=2.5cm, minimum height=1cm, text centered, text width=2.5cm, draw=black, fill=orange!0]
\tikzstyle{process5} = [rectangle, rounded corners, minimum width=2.5cm, minimum height=1cm, text centered, text width=2.5cm, draw=black, fill=orange!0]
\tikzstyle{process6} = [rectangle, rounded corners, minimum width=2.5cm, minimum height=1cm, text centered, text width=2.5cm, draw=black, fill=orange!0]
\tikzstyle{process7} = [rectangle, rounded corners, minimum width=2cm, minimum height=1.0cm, text centered, text width=2cm, draw=black, fill=orange!0]
\tikzstyle{process8} = [rectangle, rounded corners, minimum width=1cm, minimum height=1.0cm, text centered, text width=1cm, draw=black, fill=orange!0]
\tikzstyle{arrow} = [thick,->,>=stealth]
%-----------------------------------------------
\begin{document}
\begin{landscape}
\begin{figure}[htb]
\centering
\begin{adjustbox}{width=29.5cm, height=\textheight, keepaspectratio}
\begin{tikzpicture}[node distance=2cm][scale=0.01,anchor=center]
\node (start) [startstop] {\textbf{A}};
\node (pro2) [process, below = of start]{C};
\node (pro1) [process2, left = of pro2]{B};
\node (pro3) [process3, right = of pro2]{D};
\node (pro4) [process4, below = of pro1]{E};
\node (pro5) [process5, right = 1mm of pro4]{F};
\node (pro6) [process6, right = 1mm of pro5]{G};
\node (pro7) [process7, right = 1mm of pro6]{H};
\node (pro8) [process8, right = 1mm of pro7]{I};
\draw [arrow] (start) -- (pro1.north);
\draw [arrow] (start) -- (pro2.north);
\draw [arrow] (start) -- (pro3.north);
\draw [arrow] (pro2) -- (pro4.north);
\draw [arrow] (pro2) -- (pro5.north);
\draw [arrow] (pro2) -- (pro6.north);
\draw [arrow] (pro2) -- (pro7.north);
\draw [arrow] (pro2) -- (pro8.north);
\end{tikzpicture}
\end{adjustbox}
\caption{Hello}
\end{figure}
\end{landscape}
\end{document}
您还可以阅读并应用:应该使用 \tikzset 还是 \tikzstyle 来定义 TikZ 样式?
答案2
它让我想起了树,所以我建议将图表绘制为树:
\documentclass{article}
%-----------------------------------------------
\usepackage{geometry}
\usepackage{tikz}
%-----------------------------------------------
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}[
base/.style = {rectangle, draw, anchor=north,
minimum width=25mm, minimum height=10mm, align=center},
startstop/.style = {base, minimum height=1.5cm},
process/.style = {base, rounded corners},
process2/.style = {base, rounded corners, minimum size=1cm},
edge from parent/.style = {thick,-stealth},
%
level distance = 22mm,
level 1/.style = {sibling distance=42mm},
level 2/.style = {sibling distance=28mm},
]
\node (start) [startstop] {\textbf{A}}
child{ node [base] {B}}
child{ node [base] {C}
child{ node [process] {E}}
child{ node [process] {F}}
child{ node [process] {G}}
child{ node [process] {H}}
child{ node [process2] {I}}
}
child{ node [base] {D}}
;
\end{tikzpicture}
\caption{Hello}
\end{figure}
\end{document}
注意:对于节点样式,我使用最新的样式语法。减少样式数量(大多数样式在您的姆韦具有相同的样式)。在纵向页面方向上,获取的图表宽度小于文本宽度。
答案3
问题很简单,就是你的图片对于该空间来说太大了。如果将每个都cm
替换为mm
,则图片将居中。