如何更改 tikz 树的字体大小

如何更改 tikz 树的字体大小

是否有可能直接在以下树的行上更改文本的字体大小?我想缩小它,这样树就不会显得那么大。我希望有人能帮助我。谢谢!!

在此处输入图片描述

\documentclass[a4paper, 12pt, oneside, titlepage]{scrbook}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{qtree}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{acronym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow,array} 
\usepackage{colortbl}
\usepackage{anyfontsize}

\begin{document}

\begin{center}
\begin{tikzpicture}[
 dot/.style={circle, fill=black, inner sep=0pt, minimum size=7pt}, 
ring/.style={circle, draw, inner sep=0pt, minimum size=7pt}
                ]

\node[dot,pin=90:{Spieler 1}] (n11) at (0,0) {};

\node[dot,pin=135:{Spieler 2}] (n21) at (-4,-1) {};
\node[ring] (n22) at (4,-1) {};

\node[dot,label=-90:{$(0,0)$}] (n31) at (-6,-4) {};
\node[ring] (n32) at (-2,-4) {};
\node[dot,label=-90:{$(-1,1)$}] (n33) at (2,-4) {};
\node[dot,pin=50:{Spieler 2}] (n34) at (6,-4) {};

\node[dot,label=-90:{$(1,-1)$}] (n41) at (-4,-7) {};
\node[dot,label=-90:{$(-2,2)$}] (n42) at (0,-7) {};
\node[ring] (n43) at (4,-7) {};
\node[dot,label=-90:{$(0.5,-0.5)$}] (n44) at (8,-7) {};

\node[dot,label=-90:{$(1,-1)$}] (n51) at (2,-10) {};
\node[dot,label=-90:{$(0,0)$}] (n52) at (6,-10) {};

\draw (n11) -- node[above,sloped] {passen} (n21);
\draw[dotted] (n11) -- node[above,sloped] {drehen} (n22);

\draw (n21) -- node[above,sloped] {passen} (n31);
\draw (n21) -- node[above,sloped] {drehen} (n32);
\draw (n22) -- node[above,sloped] {Schuss} node[below,sloped]{$\tfrac{1}{6}$} (n33);
\draw (n22) -- node[above,sloped] {kein Schuss} node[below,sloped]{$\tfrac{5}{6}$} (n34);

\draw (n32) -- node[above,sloped] {Schuss} node[below,sloped]{$\tfrac{1}{6}$} (n41);
\draw (n32) -- node[above,sloped] {kein Schuss} node[below,sloped]{$\tfrac{5}{6}$} (n42);
\draw[dotted] (n34) -- node[above,sloped] {drehen} (n43);
\draw (n34) -- node[above,sloped] {passen} (n44);

\draw (n43) -- node[above,sloped] {Schuss} node[below,sloped]{$\tfrac{1}{6}$} (n51);
\draw (n43) -- node[above,sloped] {kein Schuss} node[below,sloped]{$\tfrac{5}{6}$} (n52);
\end{tikzpicture}
\end{center}

\end{document}

答案1

让节点中的 texz 字体大小变小很简单。我想到两种可能的解决方案:

  • 定义节点样式,类似于edgenode/.style = {above,sloped,font=\small}然后相应地命名节点,例如node[edgenode] {....}

  • 收集范围内的那些节点,在其中为范围内的每个节点进行定义。

第二种选择的完整代码是:

\documentclass[a4paper, 12pt, oneside, titlepage]{scrbook}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{qtree}
\usepackage{tikz}
\usetikzlibrary{fit}
\usepackage{acronym}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{multirow,array}
\usepackage{colortbl}
\usepackage{anyfontsize}

\begin{document}
    \begin{center}
\begin{tikzpicture}[
 dot/.style={circle, fill=black, inner sep=0pt, minimum size=7pt},
ring/.style={circle, draw, inner sep=0pt, minimum size=7pt}
                ]

\node[dot,pin=90:{Spieler 1}] (n11) at (0,0) {};

\node[dot,pin=135:{Spieler 2}] (n21) at (-4,-1) {};
\node[ring] (n22) at (4,-1) {};

\node[dot,label=-90:{$(0,0)$}] (n31) at (-6,-4) {};
\node[ring] (n32) at (-2,-4) {};
\node[dot,label=-90:{$(-1,1)$}] (n33) at (2,-4) {};
\node[dot,pin=50:{Spieler 2}] (n34) at (6,-4) {};

\node[dot,label=-90:{$(1,-1)$}] (n41) at (-4,-7) {};
\node[dot,label=-90:{$(-2,2)$}] (n42) at (0,-7) {};
\node[ring] (n43) at (4,-7) {};
\node[dot,label=-90:{$(0.5,-0.5)$}] (n44) at (8,-7) {};

\node[dot,label=-90:{$(1,-1)$}] (n51) at (2,-10) {};
\node[dot,label=-90:{$(0,0)$}] (n52) at (6,-10) {};

    \begin{scope}[every node/.style={above,sloped,
                                     font=\footnotesize% <-- desired size
                                     }]
\draw (n11) -- node {passen} (n21);
\draw[dotted] (n11) -- node {drehen} (n22);

\draw (n21) -- node {passen} (n31);
\draw (n21) -- node {drehen} (n32);
\draw (n22) -- node {Schuss} node[below,sloped]{$\tfrac{1}{6}$} (n33);
\draw (n22) -- node {kein Schuss} node[below,sloped]{$\tfrac{5}{6}$} (n34);

\draw (n32) -- node {Schuss} node[below,sloped]{$\tfrac{1}{6}$} (n41);
\draw (n32) -- node {kein Schuss} node[below,sloped]{$\tfrac{5}{6}$} (n42);
\draw[dotted] (n34) -- node {drehen} (n43);
\draw (n34) -- node {passen} (n44);

\draw (n43) -- node {Schuss} node[below,sloped]{$\tfrac{1}{6}$} (n51);
\draw (n43) -- node {kein Schuss} node[below,sloped]{$\tfrac{5}{6}$} (n52);
    \end{scope}
\end{tikzpicture}
    \end{center}
\end{document}    

在此处输入图片描述

相关内容