TikZ:如何使用 scrartcl 类将文本置于节点的中心

TikZ:如何使用 scrartcl 类将文本置于节点的中心

在此处输入图片描述

我想画一个概率树。在 Beamer 中看起来不错。但在 scrartcl 中,节点中的文本是右对齐的。我希望文本居中。我该如何解决这个问题?

\documentclass[a4paper,11pt,fleqn]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage{ntheorem}
\usepackage{here}
\usepackage{multirow}
\usepackage{eurosym}
\usepackage{graphicx}
\usepackage{array}
\usepackage{colortbl}
\usepackage[ngerman]{babel}
\usepackage{geometry}
\newcommand{\changefont}[3]{
\fontfamily{#1} \fontseries{#2} \fontshape{#3} \selectfont}
\geometry{a4paper, top=15mm, left=25mm, right=25mm, bottom=20mm,
headsep=10mm, footskip=12mm}
\theoremstyle{break}
\newtheorem{def1}{Definition}[section]
\usepackage{amsfonts}
\usepackage{color}  
\usepackage{tikz}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{shadows}
\pagestyle{empty}
\usepackage{booktabs}
\usepackage{amssymb}
\usepackage{amsmath}
\addtokomafont{caption}{\footnotesize}
\setlength{\mathindent}{0pt}
\makeatletter
\g@addto@macro\normalsize{%
  \setlength\abovedisplayskip{0pt}
  \setlength\belowdisplayskip{10pt}
  \setlength\abovedisplayshortskip{0pt}
  \setlength\belowdisplayshortskip{20pt}
}
\makeatother
\setlength{\intextsep}{0pt}

\begin{document}
\begin{center}
\begin{tikzpicture}[-,>=stealth',shorten >=0.5pt,auto,minimum size=0.3cm,inner sep=0pt,node distance=4cm,
  thick,main node/.style={circle,fill=red!20,drop shadow,draw,font=\sffamily\normalsize\bfseries}]
  \coordinate[] (1) {};
  \node[main node] (2) [right of=1,yshift=2.1cm] {$R$};
  \node[main node] (3) [right of=1,yshift=-2.1cm] {$F$};
  \node[main node] (4) [right of=2,yshift=1.1cm] {$R$};
  \node[main node] (5) [right of=2,yshift=-1.1cm] {$F$};
  \node[main node] (6) [right of=3,yshift=1.1cm] {$R$};
  \node[main node] (7) [right of=3,yshift=-1.1cm] {$F$};
  \path[every node/.style={font=\sffamily\small}]
    (1) edge [] node[above]{\footnotesize $0,5$} (2)
    (1) edge [] node[below,yshift=-2pt]{\footnotesize $0,5$} (3)
    (2) edge [] node[above]{\footnotesize $0,5$} (4)
    (2) edge [] node[below]{\footnotesize $0,5$} (5)
    (3) edge [] node[above]{\footnotesize $0,5$} (6)
    (3) edge [] node[below]{\footnotesize $0,5$} (7);
\end{tikzpicture}
\end{center}
\end{document}

答案1

您有很多尾随空格。使用:

\makeatletter
\g@addto@macro\normalsize{%  <----
  \setlength\abovedisplayskip{0pt}%  <----
  \setlength\belowdisplayskip{10pt}%  <----
  \setlength\abovedisplayshortskip{0pt}%  <----
  \setlength\belowdisplayshortskip{20pt}%  <----
}
\makeatother

您正在使用\normalsize节点文本

相关内容