0

I am now doing a chart. And I want to position the node A in the middle and keep the other nodes unchanged. However, neither \begin{center}...\end{center} nor \centering are working. Any idea how to solve this? Thanks a lot.

\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}

enter image description here

Sebastiano
  • 54,118
Daniel Chan
  • 191
  • 10

3 Answers3

2

Your original code says:

\node (start) [startstop] {\textbf{A}};
\node (pro1) [process, below of=start, yshift=-1cm]{B};

which means place node pro1 below node start. Therefore, it's B which is below A and not C. If you want C below A place it and then place B to the left of C and D to the right.

By the way, you're loading positioning library but using the deprecated syntax below of = ... instead of new below = of ....

Please read Difference between "right of=" and "right=of" in PGF/TikZ

I've replaced old by new and the result looks like:

enter image description here

\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}

You could also read and apply: Should \tikzset or \tikzstyle be used to define TikZ styles?

Ignasi
  • 136,588
  • thanks for the answer. I appreciate. One follow up question, is it possible to fix node A in the middle. Because i am trying to narrow down the node distance between B-C and C-D. However, A will move to the side when i change the distance between B-C and C-D. – Daniel Chan Jan 19 '18 at 10:57
  • @DanielChan I don't understand. If C is below A and distance B-C is equal to distance C-D, A will be in the middle whatever be the distance B-C (C-D). – Ignasi Jan 19 '18 at 11:22
  • i think i got the solution. Sorry for the misunderstanding – Daniel Chan Jan 20 '18 at 07:41
2

its remind me on tree, so i suggest to draw your chart as tree:

enter image description here

\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}

note: for nodes styles i use recent syntax for styles. reduce number of styles (most of them in your mwe have the same style). the width of obtained chart is smaller than text width in portrait page orientation.

Zarko
  • 296,517
0

The problem is simply that your image is too large for that space. If every cm is replaced by mm, then the image is centered.

  • still not working. i just want to move node A on top of node C. i am sorry if my question is a bit mis-leading. – Daniel Chan Jan 19 '18 at 10:31