26

I made a small tkzpicture as in the SWE below. How may I rotate it 90 positive degrees?

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

%\pagestyle{empty}
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=gray!20, text width=7.5em, rounded corners, minimum height=4.1em]
\tikzstyle{blocks} = [rectangle, fill=white!20, text width=9em, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [ellipse,fill=white!20, node distance=2cm,
    minimum height=2em]


\begin{tikzpicture}[node distance = 2cm, auto]

    %\node [block] (initial) {Initial text};
    \node [block] (beginning) {{\tiny Beginning}};
    \node [cloud, below of =beginning] (decide) {Reactions};
    \node [block, below of=decide, node distance=3cm](stop){{\tiny \textbf{Second alternative}: Wait }};
    \node[block, left of =stop, node distance=3cm](left){{\tiny \textbf{First alternative}: Continue}};
    \node[block, right of =stop, node distance=3cm](right){{\tiny \textbf{Third alternative}: Give in }};
    \node[blocks, below of =left, node distance=2cm](node name){{\large Logo}};  
    %\path [line] (initial) -- (evaluate);
    \path [line] (beginning) -- (decide);
    \path [line] (decide) -- node {}(stop);
    \path [line](decide)--(right);
    \path [line](decide)--(left);
\end{tikzpicture}

\end{document}

3 Answers 3

30

You can use the rotate key, but you also need transform shape or nodes are not rotated:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

%\pagestyle{empty}
\tikzstyle{decision} = [diamond, draw, fill=blue!20,
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=gray!20, text width=7.5em, rounded corners, minimum height=4.1em]
\tikzstyle{blocks} = [rectangle, fill=white!20, text width=9em, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [ellipse,fill=white!20, node distance=2cm,
    minimum height=2em]


\begin{tikzpicture}[node distance = 2cm, auto,rotate=90,transform shape]

    %\node [block] (initial) {Initial text};
    \node [block] (beginning) {{\tiny Beginning}};
    \node [cloud, below of =beginning] (decide) {Reactions};
    \node [block, below of=decide, node distance=3cm](stop){{\tiny \textbf{Second alternative}: Wait }};
    \node[block, left of =stop, node distance=3cm](left){{\tiny \textbf{First alternative}: Continue}};
    \node[block, right of =stop, node distance=3cm](right){{\tiny \textbf{Third alternative}: Give in }};
    \node[blocks, below of =left, node distance=2cm](node name){{\large Logo}};
    %\path [line] (initial) -- (evaluate);
    \path [line] (beginning) -- (decide);
    \path [line] (decide) -- node {}(stop);
    \path [line](decide)--(right);
    \path [line](decide)--(left);
\end{tikzpicture}

\end{document}

enter image description here

6

Note that most of the time wrapping a tikzpicture inside a tikzpicture is a bad idea, this is not officially supported!

Funny solution: Wrapping a tikzpicture in a tikzpicture node which is rotated by 90 degrees:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\begin{document}

%\pagestyle{empty}
\tikzset{
  ,decision/.style=
    {
      diamond, draw, fill=blue!20, text width=4.5em, text badly centered, 
      node distance=3cm, inner sep=0pt
    }
  ,block/.style=
    {
      rectangle, draw, fill=gray!20, text width=7.5em, rounded corners, 
      minimum height=4.1em
    }
  ,blocks/.style=
    {
      rectangle, fill=white!20, text width=9em, rounded corners,
      minimum height=4em
    }
  ,line/.style={draw, -latex'}
  ,cloud/.style={ellipse,fill=white!20, node distance=2cm, minimum height=2em}
}

\begin{tikzpicture}
  \node[rotate=90] at (0,0) {
    \begin{tikzpicture}[node distance = 2cm, auto]

        %\node [block] (initial) {Initial text};
        \node [block] (beginning) {{\tiny Beginning}};
        \node [cloud, below of =beginning] (decide) {Reactions};
        \node [block, below of=decide, node distance=3cm](stop){{\tiny \textbf{Second alternative}: Wait }};
        \node[block, left of =stop, node distance=3cm](left){{\tiny \textbf{First alternative}: Continue}};
        \node[block, right of =stop, node distance=3cm](right){{\tiny \textbf{Third alternative}: Give in }};
        \node[blocks, below of =left, node distance=2cm](node name){{\large Logo}};  
        %\path [line] (initial) -- (evaluate);
        \path [line] (beginning) -- (decide);
        \path [line] (decide) -- node {}(stop);
        \path [line](decide)--(right);
        \path [line](decide)--(left);
    \end{tikzpicture}
  };
\end{tikzpicture}

\end{document}
6
  • @marmot \rotatebox didn't work for me. The other tips should be implemented, give me a second :)
    – Skillmon
    Commented Jun 28, 2018 at 22:07
  • @marmot I would have posted it if it did work for me. Feel free to post your answer :)
    – Skillmon
    Commented Jun 28, 2018 at 22:10
  • You are right that it won't work in the OP's document, but of course the first thing I did was to remove the \usepackage[active,tightpage]{preview} \PreviewEnvironment{tikzpicture} stuff, and then \rotatebox{90}{...} does work. ;-)
    – user121799
    Commented Jun 28, 2018 at 22:36
  • @marmot funny thing, as soon as anything boxes the tikzpicture the rotation doesn't work for me. And removing the preview might not be what OP wants.
    – Skillmon
    Commented Jun 28, 2018 at 22:38
  • 2
    Nesting tikzpicture is highly not recommended. Commented Jun 29, 2018 at 0:16
3

With standalone document class as cropping element instead of preview package, you can include the tikzpicture inside a rotatebox command to get the desired result.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
%\usepackage[active,tightpage]{preview}
%\PreviewEnvironment{tikzpicture}

\begin{document}

%\pagestyle{empty}
\tikzstyle{decision} = [diamond, draw, fill=blue!20, 
    text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
\tikzstyle{block} = [rectangle, draw, fill=gray!20, text width=7.5em, rounded corners, minimum height=4.1em]
\tikzstyle{blocks} = [rectangle, fill=white!20, text width=9em, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
\tikzstyle{cloud} = [ellipse,fill=white!20, node distance=2cm,
    minimum height=2em]


\rotatebox{90}{%
\begin{tikzpicture}[node distance = 2cm, auto]

    %\node [block] (initial) {Initial text};
    \node [block] (beginning) {{\tiny Beginning}};
    \node [cloud, below of =beginning] (decide) {Reactions};
    \node [block, below of=decide, node distance=3cm](stop){{\tiny \textbf{Second alternative}: Wait }};
    \node[block, left of =stop, node distance=3cm](left){{\tiny \textbf{First alternative}: Continue}};
    \node[block, right of =stop, node distance=3cm](right){{\tiny \textbf{Third alternative}: Give in }};
    \node[blocks, below of =left, node distance=2cm](node name){{\large Logo}};  
    %\path [line] (initial) -- (evaluate);
    \path [line] (beginning) -- (decide);
    \path [line] (decide) -- node {}(stop);
    \path [line](decide)--(right);
    \path [line](decide)--(left);
\end{tikzpicture}
}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .