我怎样才能旋转 tikzpicture?

我怎样才能旋转 tikzpicture?

我制作了一个小的 tkzpicture,如下面的 SWE 所示。我怎样才能将其旋转正 90 度?

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

答案1

您可以使用旋转键,但您还需要transform shape或节点不会旋转:

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

在此处输入图片描述

答案2

请注意,大多数时候将 a 包装tikzpicture在 a 里面tikzpicture是个坏主意,这不受官方支持!

有趣的解决方案:将一个节点包装在旋转 90 度的节点tikzpicture中:tikzpicture

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

答案3

使用standalone文档类而不是preview包作为裁剪元素,您可以tikzpicturerotatebox命令中包含它以获得所需的结果。

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

在此处输入图片描述

相关内容