3

I wrote a large game tree (using automata package) and need to display it in landscape mode. I already tried to use both textpos and geometry (newgeometry command) packages but without any positive results. I need to shift the picture to the left so the right part of the game tree displays properly. Any suggestions? Also if there is a way to fit it in portrait mode it would be even better. Here is the code:

\documentclass[12pt]{exam}
\usepackage{tikz}
\usepackage{pgf}
\usepackage{geometry}
\usepackage{textpos} 
\usepackage{pdflscape}
\usetikzlibrary{external,automata,trees,positioning,shadows,arrows,shapes.geometric}
\begin{document}

\begin{landscape}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                semithick]
\tikzstyle{every state}=[fill,draw=none,green,text=white,circular drop shadow]
\tikzstyle{accepting}=[circle split, draw,text=black,inner sep=0.08cm]
\tikzstyle{initial}=[red,text=white]
\node[state,initial]  (N0) {Nature};
\node[state]   (N1) [below left of=N0,xshift=-5cm]  {Nature};
\node[state]   (F1) [below left of=N1]  {R\&G};
\node[state]   (K1) [below right of=N1] {R\&G};
\node[state]   (FS1) [below left of=F1]  {H};
\node[accepting]    (FN1) [above left of=F1] {\phantom{1}};
\node[state]        (KS1) [below right of=K1]  {H};
\node[accepting]    (KN1) [above right of=K1] {\phantom{1}};
\node[accepting]    (FSC1) [below left of=FS1]  {\phantom{1}};
\node[accepting]    (FSN1) [above left of=FS1] {\phantom{1}};
\node[accepting]    (KSC1) [below right of=KS1]  {\phantom{1}};
\node[accepting]    (KSN1) [above right of=KS1] {\phantom{1}};

\path(N1) edge node[ above left, pos=.20]{feed Hamlet}  node[ below right, pos=.30]{0} (F1) 
edge node[above right, pos=.20]{kill Hamlet} node[below left, pos=.30]{1} (K1);
\path(F1) edge node[above left,pos=.5]{escort} (FS1) edge node[ left]{don't}(FN1);
\path(K1) edge node[above right,pos=.5]{escort} (KS1) edge node[ right]{don't}(KN1);
\path(FS1) edge node[above left]{change} (FSC1) edge node[ left]{don't}(FSN1);
\path(KS1) edge node[above right]{change} (KSC1) edge node[ right]{don't}(KSN1);
\path(K1) edge[thick,dotted,-](F1);

 \node[state]   (N)[below right of=N0,xshift=5cm]  {Nature};
 \node[state]    (F) [below left of=N]  {R\&G};
 \node[state]    (K) [below right of=N] {R\&G};
 \node[state]    (FS) [below left of=F]  {H};
 \node[accepting]    (FN) [above left of=F] {\phantom{1}};
 \node[state]    (KS) [below right of=K]  {H};
 \node[accepting]     (KN) [above right of=K] {\phantom{1}};
  \node[accepting]    (FSC) [below left of=FS]  {\phantom{1}};
 \node[accepting]    (FSN) [above left of=FS] {\phantom{1}};
 \node[accepting]    (KSC) [below right of=KS]  {\phantom{1}};
 \node[accepting]     (KSN) [above right of=KS] {\phantom{1}};

 \path(N) edge node[ above left, pos=.20]{feed Hamlet}  node[ below right, pos=.30]{0} (F) 
edge node[above right, pos=.20]{kill Hamlet} node[below left, pos=.30]{1} (K);
 \path(F) edge node[above left,pos=.5]{escort} (FS) edge node[ left]{don't}(FN);
 \path(K) edge node[above right,pos=.5]{escort} (KS) edge node[ right]{don't}(KN);
 \path(FS) edge node[above left]{change} (FSC) edge node[ left]{don't}(FSN);
 \path(KS) edge node[above right]{change} (KSC) edge node[ right]{don't}(KSN);
 \path(K) edge[thick,dotted,-](F);

\end{tikzpicture}
\end{landscape}
\end{document}
  • 1
    Please make your code compilable, starting with \documentclass{...}, loading all the required packages (but only the required ones), etc. Otherwise, people who want to help you have to do it themselves. Help them help you :) – jub0bs May 4 '13 at 21:55
  • Could you please pass the option paperheight=35cm to geometry package: \usepackage[paperwidth=35cm]{geometry} and see how it looks. – kan May 4 '13 at 22:52
  • Thanks Kan: that works and it is also a nice hack to use for future projects. – Sergio Parreiras May 5 '13 at 1:49
  • You can use current page.xxx to specify coordinates of nodes, which is useful for page-based alignment. – SaltyEgg May 5 '13 at 4:59
6

A solution without \resizebox because with this macro, the text is resized. I try to use landscape environment like you. The problem is to know if you need to use this tree in a big document or alone.

1) parindent=0pt to extra horizontal space.

2) \eject\null try to put the box on a new page in vertical mode; now it's possible to use \vfill around the box.

3) \hspace*{-4cm} i don't know exactly what is the layout used by the class exam, so I search by hand a good dimension to center the box without the left margin.

4) I reduced a little node distance here 2.5cm instead of 2.8cm perhaps it's possible to reduce again but you need in this case change the place of some texts.

\documentclass[12pt]{exam}
\usepackage{tikz}
\usepackage{geometry}
\usepackage{pdflscape}
\usepackage{graphicx} 
\usetikzlibrary{external,automata,trees,positioning,shadows,arrows,shapes.geometric}

\newlength\Textht
\setlength\Textht{\textheight}

\begin{document}

\begin{landscape}
\parindent=0pt
\eject\null
\vfill
\hspace*{-4cm}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,
                semithick]
\tikzstyle{every state}=[fill,draw=none,green,text=white,circular drop shadow]
\tikzstyle{accepting}=[circle split, draw,text=black,inner sep=0.08cm]
\tikzstyle{initial}=[red,text=white]
\node[state,initial]  (N0) {Nature};
\node[state]        (N1)   [below left  of=N0,xshift=-5cm]  {Nature};
\node[state]        (F1)   [below left  of=N1]  {R\&G};
\node[state]        (K1)   [below right of=N1]  {R\&G};
\node[state]        (FS1)  [below left  of=F1]  {H};
\node[accepting]    (FN1)  [above left  of=F1]  {\phantom{1}};
\node[state]        (KS1)  [below right of=K1]  {H};
\node[accepting]    (KN1)  [above right of=K1]  {\phantom{1}};
\node[accepting]    (FSC1) [below left  of=FS1] {\phantom{1}};
\node[accepting]    (FSN1) [above left  of=FS1] {\phantom{1}};
\node[accepting]    (KSC1) [below right of=KS1] {\phantom{1}};
\node[accepting]    (KSN1) [above right of=KS1] {\phantom{1}};

\path(N1) edge node[ above left, pos=.20]{feed Hamlet}  node[ below right, pos=.30]{0} (F1) 
edge node[above right, pos=.20]{kill Hamlet} node[below left, pos=.30]{1} (K1);
\path(F1) edge node[above left,pos=.5]{escort} (FS1) edge node[ left]{don't}(FN1);
\path(K1) edge node[above right,pos=.5]{escort} (KS1) edge node[ right]{don't}(KN1);
\path(FS1) edge node[above left]{change} (FSC1) edge node[ left]{don't}(FSN1);
\path(KS1) edge node[above right]{change} (KSC1) edge node[ right]{don't}(KSN1);
\path(K1) edge[thick,dotted,-](F1);

 \node[state]        (N)   [below right of=N0,xshift=5cm]  {Nature};
 \node[state]        (F)   [below left  of=N]  {R\&G};
 \node[state]        (K)   [below right of=N] {R\&G};
 \node[state]        (FS)  [below left  of=F]  {H};
 \node[accepting]    (FN)  [above left  of=F] {\phantom{1}};
 \node[state]        (KS)  [below right of=K]  {H};
 \node[accepting]    (KN)  [above right of=K] {\phantom{1}};
 \node[accepting]    (FSC) [below left  of=FS]  {\phantom{1}};
 \node[accepting]    (FSN) [above left  of=FS] {\phantom{1}};
 \node[accepting]    (KSC) [below right of=KS]  {\phantom{1}};
 \node[accepting]    (KSN) [above right of=KS] {\phantom{1}};

 \path(N) edge node[ above left, pos=.20]{feed Hamlet}  node[ below right, pos=.30]{0} (F) 
edge node[above right, pos=.20]{kill Hamlet} node[below left, pos=.30]{1} (K);
 \path(F) edge node[above left,pos=.5]{escort} (FS) edge node[ left]{don't}(FN);
 \path(K) edge node[above right,pos=.5]{escort} (KS) edge node[ right]{don't}(KN);
 \path(FS) edge node[above left]{change} (FSC) edge node[ left]{don't}(FSN);
 \path(KS) edge node[above right]{change} (KSC) edge node[ right]{don't}(KSN);
 \path(K) edge[thick,dotted,-](F);
\end{tikzpicture}%
\hfill
\vfill
\end{landscape}
\end{document}

enter image description here

4

You can use \resizebox from the graphicx package; since in landscape mode the width and the height get swapped you need to use the original \textheight as the new width for the resizing:

\documentclass[12pt]{exam}
\usepackage{tikz}
\usepackage{geometry}
\usepackage{graphicx} 
\usetikzlibrary{external,automata,trees,positioning,shadows,arrows,shapes.geometric}

\newlength\Textht
\setlength\Textht{\textheight}

\begin{document}

\begin{landscape}
\null\vfill

\noindent\resizebox{\Textht}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                semithick]
\tikzstyle{every state}=[fill,draw=none,green,text=white,circular drop shadow]
\tikzstyle{accepting}=[circle split, draw,text=black,inner sep=0.08cm]
\tikzstyle{initial}=[red,text=white]
\node[state,initial]  (N0) {Nature};
\node[state]   (N1) [below left of=N0,xshift=-5cm]  {Nature};
\node[state]   (F1) [below left of=N1]  {R\&G};
\node[state]   (K1) [below right of=N1] {R\&G};
\node[state]   (FS1) [below left of=F1]  {H};
\node[accepting]    (FN1) [above left of=F1] {\phantom{1}};
\node[state]        (KS1) [below right of=K1]  {H};
\node[accepting]    (KN1) [above right of=K1] {\phantom{1}};
\node[accepting]    (FSC1) [below left of=FS1]  {\phantom{1}};
\node[accepting]    (FSN1) [above left of=FS1] {\phantom{1}};
\node[accepting]    (KSC1) [below right of=KS1]  {\phantom{1}};
\node[accepting]    (KSN1) [above right of=KS1] {\phantom{1}};

\path(N1) edge node[ above left, pos=.20]{feed Hamlet}  node[ below right, pos=.30]{0} (F1) 
edge node[above right, pos=.20]{kill Hamlet} node[below left, pos=.30]{1} (K1);
\path(F1) edge node[above left,pos=.5]{escort} (FS1) edge node[ left]{don't}(FN1);
\path(K1) edge node[above right,pos=.5]{escort} (KS1) edge node[ right]{don't}(KN1);
\path(FS1) edge node[above left]{change} (FSC1) edge node[ left]{don't}(FSN1);
\path(KS1) edge node[above right]{change} (KSC1) edge node[ right]{don't}(KSN1);
\path(K1) edge[thick,dotted,-](F1);

 \node[state]   (N)[below right of=N0,xshift=5cm]  {Nature};
 \node[state]    (F) [below left of=N]  {R\&G};
 \node[state]    (K) [below right of=N] {R\&G};
 \node[state]    (FS) [below left of=F]  {H};
 \node[accepting]    (FN) [above left of=F] {\phantom{1}};
 \node[state]    (KS) [below right of=K]  {H};
 \node[accepting]     (KN) [above right of=K] {\phantom{1}};
  \node[accepting]    (FSC) [below left of=FS]  {\phantom{1}};
 \node[accepting]    (FSN) [above left of=FS] {\phantom{1}};
 \node[accepting]    (KSC) [below right of=KS]  {\phantom{1}};
 \node[accepting]     (KSN) [above right of=KS] {\phantom{1}};

 \path(N) edge node[ above left, pos=.20]{feed Hamlet}  node[ below right, pos=.30]{0} (F) 
edge node[above right, pos=.20]{kill Hamlet} node[below left, pos=.30]{1} (K);
 \path(F) edge node[above left,pos=.5]{escort} (FS) edge node[ left]{don't}(FN);
 \path(K) edge node[above right,pos=.5]{escort} (KS) edge node[ right]{don't}(KN);
 \path(FS) edge node[above left]{change} (FSC) edge node[ left]{don't}(FSN);
 \path(KS) edge node[above right]{change} (KSC) edge node[ right]{don't}(KSN);
 \path(K) edge[thick,dotted,-](F);

\end{tikzpicture}%
}
\vfill
\end{landscape}

\end{document}

enter image description here

I also used some \vfill commands to vertically center the tikzpicture, but those are optional. Notice also that, since you are loading tikz, there's no need to explicitly load pgf.

The same command can be used to resize your tree in portrait mode:

\documentclass[12pt]{exam}
\usepackage{tikz}
\usepackage{geometry}
\usepackage{graphicx} 
\usepackage{pdflscape}
\usetikzlibrary{external,automata,trees,positioning,shadows,arrows,shapes.geometric}

\begin{document}

\noindent\resizebox{\textwidth}{!}{%
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
                semithick]
\tikzstyle{every state}=[fill,draw=none,green,text=white,circular drop shadow]
\tikzstyle{accepting}=[circle split, draw,text=black,inner sep=0.08cm]
\tikzstyle{initial}=[red,text=white]
\node[state,initial]  (N0) {Nature};
\node[state]   (N1) [below left of=N0,xshift=-5cm]  {Nature};
\node[state]   (F1) [below left of=N1]  {R\&G};
\node[state]   (K1) [below right of=N1] {R\&G};
\node[state]   (FS1) [below left of=F1]  {H};
\node[accepting]    (FN1) [above left of=F1] {\phantom{1}};
\node[state]        (KS1) [below right of=K1]  {H};
\node[accepting]    (KN1) [above right of=K1] {\phantom{1}};
\node[accepting]    (FSC1) [below left of=FS1]  {\phantom{1}};
\node[accepting]    (FSN1) [above left of=FS1] {\phantom{1}};
\node[accepting]    (KSC1) [below right of=KS1]  {\phantom{1}};
\node[accepting]    (KSN1) [above right of=KS1] {\phantom{1}};

\path(N1) edge node[ above left, pos=.20]{feed Hamlet}  node[ below right, pos=.30]{0} (F1) 
edge node[above right, pos=.20]{kill Hamlet} node[below left, pos=.30]{1} (K1);
\path(F1) edge node[above left,pos=.5]{escort} (FS1) edge node[ left]{don't}(FN1);
\path(K1) edge node[above right,pos=.5]{escort} (KS1) edge node[ right]{don't}(KN1);
\path(FS1) edge node[above left]{change} (FSC1) edge node[ left]{don't}(FSN1);
\path(KS1) edge node[above right]{change} (KSC1) edge node[ right]{don't}(KSN1);
\path(K1) edge[thick,dotted,-](F1);

 \node[state]   (N)[below right of=N0,xshift=5cm]  {Nature};
 \node[state]    (F) [below left of=N]  {R\&G};
 \node[state]    (K) [below right of=N] {R\&G};
 \node[state]    (FS) [below left of=F]  {H};
 \node[accepting]    (FN) [above left of=F] {\phantom{1}};
 \node[state]    (KS) [below right of=K]  {H};
 \node[accepting]     (KN) [above right of=K] {\phantom{1}};
  \node[accepting]    (FSC) [below left of=FS]  {\phantom{1}};
 \node[accepting]    (FSN) [above left of=FS] {\phantom{1}};
 \node[accepting]    (KSC) [below right of=KS]  {\phantom{1}};
 \node[accepting]     (KSN) [above right of=KS] {\phantom{1}};

 \path(N) edge node[ above left, pos=.20]{feed Hamlet}  node[ below right, pos=.30]{0} (F) 
edge node[above right, pos=.20]{kill Hamlet} node[below left, pos=.30]{1} (K);
 \path(F) edge node[above left,pos=.5]{escort} (FS) edge node[ left]{don't}(FN);
 \path(K) edge node[above right,pos=.5]{escort} (KS) edge node[ right]{don't}(KN);
 \path(FS) edge node[above left]{change} (FSC) edge node[ left]{don't}(FSN);
 \path(KS) edge node[above right]{change} (KSC) edge node[ right]{don't}(KSN);
 \path(K) edge[thick,dotted,-](F);

\end{tikzpicture}%
}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.