Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/GraphicalSymbolicExpressionTreeView.Designer.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/GraphicalSymbolicExpressionTreeView.Designer.cs	(revision 10456)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/GraphicalSymbolicExpressionTreeView.Designer.cs	(revision 10501)
@@ -19,4 +19,6 @@
  */
 #endregion
+
+using System.Drawing;
 
 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
@@ -59,5 +61,5 @@
       this.symbolicExpressionTreeChart.Spacing = 5;
       this.symbolicExpressionTreeChart.TabIndex = 0;
-      this.symbolicExpressionTreeChart.TextFont = new System.Drawing.Font("Times New Roman", 6F);
+      this.symbolicExpressionTreeChart.TextFont = new System.Drawing.Font(FontFamily.GenericSerif, 8F);
       // 
       // FunctionTreeView
Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/GraphicalSymbolicExpressionTreeView.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/GraphicalSymbolicExpressionTreeView.cs	(revision 10456)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/GraphicalSymbolicExpressionTreeView.cs	(revision 10501)
@@ -20,5 +20,4 @@
 #endregion
 
-using System.Drawing;
 using System.Windows.Forms;
 using HeuristicLab.Core.Views;
@@ -53,12 +52,4 @@
       symbolicExpressionTreeChart.Enabled = Content != null;
     }
-
-    public void HighlightNode(ISymbolicExpressionTreeNode node, Color color) {
-      symbolicExpressionTreeChart.HighlightNode(node, color);
-    }
-
-    public void HighlightSubtree(ISymbolicExpressionTreeNode subtree, Color color) {
-      symbolicExpressionTreeChart.HighlightSubtree(subtree, color);
-    }
   }
 }
Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.Designer.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.Designer.cs	(revision 10456)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.Designer.cs	(revision 10501)
@@ -50,5 +50,5 @@
       this.saveImageToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
       this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
-      this.exportLatexToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+      this.exportPgfLaTeXToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
       this.contextMenuStrip.SuspendLayout();
       this.SuspendLayout();
@@ -58,12 +58,12 @@
       this.contextMenuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
             this.saveImageToolStripMenuItem,
-            this.exportLatexToolStripMenuItem});
+            this.exportPgfLaTeXToolStripMenuItem});
       this.contextMenuStrip.Name = "contextMenuStrip";
-      this.contextMenuStrip.Size = new System.Drawing.Size(161, 70);
+      this.contextMenuStrip.Size = new System.Drawing.Size(166, 70);
       // 
       // saveImageToolStripMenuItem
       // 
       this.saveImageToolStripMenuItem.Name = "saveImageToolStripMenuItem";
-      this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
+      this.saveImageToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
       this.saveImageToolStripMenuItem.Text = "Save Image";
       this.saveImageToolStripMenuItem.Click += new System.EventHandler(this.saveImageToolStripMenuItem_Click);
@@ -73,10 +73,10 @@
       this.saveFileDialog.Filter = "Bitmap (*.bmp)|*.bmp|EMF (*.emf)|*.emf";
       // 
-      // exportLatexToolStripMenuItem
+      // exportPgfLaTeXToolStripMenuItem
       // 
-      this.exportLatexToolStripMenuItem.Name = "exportLatexToolStripMenuItem";
-      this.exportLatexToolStripMenuItem.Size = new System.Drawing.Size(160, 22);
-      this.exportLatexToolStripMenuItem.Text = "Export Pgf/Latex";
-      this.exportLatexToolStripMenuItem.Click += new System.EventHandler(this.exportLatexToolStripMenuItem_Click);
+      this.exportPgfLaTeXToolStripMenuItem.Name = "exportPgfLaTeXToolStripMenuItem";
+      this.exportPgfLaTeXToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
+      this.exportPgfLaTeXToolStripMenuItem.Text = "Export Pgf/LaTeX";
+      this.exportPgfLaTeXToolStripMenuItem.Click += new System.EventHandler(this.exportLatexToolStripMenuItem_Click);
       // 
       // SymbolicExpressionTreeChart
@@ -102,5 +102,5 @@
     protected System.Windows.Forms.ToolStripMenuItem saveImageToolStripMenuItem;
     protected System.Windows.Forms.SaveFileDialog saveFileDialog;
-    private System.Windows.Forms.ToolStripMenuItem exportLatexToolStripMenuItem;
+    private System.Windows.Forms.ToolStripMenuItem exportPgfLaTeXToolStripMenuItem;
   }
 }
Index: branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
===================================================================
--- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs	(revision 10456)
+++ branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs	(revision 10501)
@@ -32,5 +32,5 @@
   public partial class SymbolicExpressionTreeChart : UserControl {
     private Image image;
-    private StringFormat stringFormat;
+    private readonly StringFormat stringFormat;
     private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes;
     private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines;
@@ -51,5 +51,5 @@
       this.lineColor = Color.Black;
       this.backgroundColor = Color.White;
-      this.textFont = new Font(FontFamily.GenericSerif, 14, GraphicsUnit.Pixel);
+      this.textFont = new Font(FontFamily.GenericSansSerif, 12);
       layoutEngine = new ReingoldTilfordLayoutEngine<ISymbolicExpressionTreeNode>();
       layoutAdapter = new SymbolicExpressionTreeLayoutAdapter();
@@ -108,5 +108,8 @@
         visualLines = new Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection>();
         if (tree != null) {
-          foreach (ISymbolicExpressionTreeNode node in tree.IterateNodesPrefix()) {
+          IEnumerable<ISymbolicExpressionTreeNode> nodes;
+          if (tree.Root.SubtreeCount == 1) nodes = tree.Root.GetSubtree(0).IterateNodesPrefix();
+          else nodes = tree.Root.IterateNodesPrefix();
+          foreach (ISymbolicExpressionTreeNode node in nodes) {
             visualTreeNodes[node] = new VisualSymbolicExpressionTreeNode(node);
             if (node.Parent != null) visualLines[Tuple.Create(node.Parent, node)] = new VisualSymbolicExpressionTreeNodeConnection();
@@ -166,16 +169,4 @@
         this.Refresh();
       }
-    }
-
-    public void HighlightNode(ISymbolicExpressionTreeNode node, Color color) {
-      var visualNode = GetVisualSymbolicExpressionTreeNode(node);
-      if (visualNode == null) return;
-      visualNode.LineColor = color;
-      RepaintNode(visualNode);
-    }
-
-    public void HighlightSubtree(ISymbolicExpressionTreeNode subtree, Color color) {
-      foreach (var node in subtree.IterateNodesBreadth())
-        HighlightNode(node, color);
     }
 
@@ -280,43 +271,54 @@
     private void DrawFunctionTree(ISymbolicExpressionTree symbolicExpressionTree, Graphics graphics, int preferredWidth, int preferredHeight, int minHDistance, int minVDistance) {
       var layoutNodes = layoutAdapter.Convert(symbolicExpressionTree).ToList();
+      if (symbolicExpressionTree.Root.SubtreeCount == 1) layoutNodes.RemoveAt(0);
       layoutEngine.Reset();
       layoutEngine.Root = layoutNodes[0];
-      foreach (var ln in layoutNodes)
-        layoutEngine.AddNode(ln.Content, ln);
-      layoutEngine.MinHorizontalSpacing = (preferredNodeWidth + minHDistance);
-      layoutEngine.MinVerticalSpacing = (preferredNodeHeight + minVDistance);
+      layoutEngine.AddNodes(layoutNodes);
+      layoutEngine.MinHorizontalSpacing = (preferredWidth + minHDistance);
+      layoutEngine.MinVerticalSpacing = (preferredHeight + minVDistance);
       layoutEngine.CalculateLayout();
       var bounds = layoutEngine.Bounds();
-      double sx = this.Width / (bounds.Width + preferredWidth);
-      if (sx > 1) sx = 1;
-      double sy = this.Height / bounds.Height;
-      if (sy > 1) sy = 1;
-      double dx = (this.Width - bounds.Width) / 2;
-      if (dx < 0) dx = 0;
-      double dy = (this.Height - bounds.Height) / 2;
-      if (dy < 0) dy = 0;
-
-      var levels = layoutNodes.GroupBy(n => n.Level, n => n);
-
-      foreach (var level in levels) {
-        var nodes = level.ToList();
-        double min = 0;
-        for (int i = 0; i < nodes.Count - 1; ++i) {
-          var w = (nodes[i + 1].X - nodes[i].X) * sx - preferredWidth;
-          if (w < min) min = w;
-        }
-        if (min > 0) min = 0;
-
-        foreach (var layoutNode in level) {
+
+      double verticalScalingFactor = 1.0;
+      double layoutHeight = (bounds.Height + preferredHeight);
+      if (this.Height < layoutHeight)
+        verticalScalingFactor = this.Height / layoutHeight;
+
+      double horizontalScalingFactor = 1.0;
+      double layoutWidth = (bounds.Width + preferredWidth);
+      if (this.Width < layoutWidth)
+        horizontalScalingFactor = this.Width / layoutWidth;
+
+      double horizontalOffset;
+      if (this.Width > layoutWidth)
+        horizontalOffset = (this.Width - layoutWidth) / 2.0;
+      else
+        horizontalOffset = preferredWidth / 2.0;
+
+      var levels = layoutNodes.GroupBy(n => n.Level, n => n).ToList();
+      for (int i = levels.Count - 1; i >= 0; --i) {
+        var nodes = levels[i].ToList();
+
+        double minSpacing = double.MaxValue;
+        if (nodes.Count > 1) {
+          for (int j = 1; j < nodes.Count() - 1; ++j) {
+            var distance = nodes[j].X - nodes[j - 1].X; // guaranteed to be > 0
+            if (minSpacing > distance) minSpacing = distance;
+          }
+        }
+        minSpacing *= horizontalScalingFactor;
+
+        int minWidth = (int)Math.Round(preferredWidth * horizontalScalingFactor);
+        int width = (int)Math.Min(minSpacing, preferredWidth) - 2; // leave some pixels so that node margins don't overlap
+
+        foreach (var layoutNode in nodes) {
           var visualNode = visualTreeNodes[layoutNode.Content];
-          visualNode.Width = (int)Math.Round(preferredWidth + min) - 2; // -2 to allow enough padding (1px on each side) for the node contour to be drawn
-          visualNode.Height = (int)Math.Round(preferredHeight * sy);
-          visualNode.X = (int)(Math.Round(layoutNode.X * sx + dx));
-          visualNode.Y = (int)(Math.Round(layoutNode.Y * sy + dy));
+          visualNode.Width = width;
+          visualNode.Height = (int)Math.Round(preferredHeight * verticalScalingFactor);
+          visualNode.X = (int)Math.Round((layoutNode.X + horizontalOffset) * horizontalScalingFactor + (minWidth - width) / 2.0);
+          visualNode.Y = (int)Math.Round(layoutNode.Y * verticalScalingFactor);
           DrawTreeNode(graphics, visualNode);
         }
       }
-
-      graphics.ResetClip(); // reset clip region
       // draw node connections
       foreach (var visualNode in visualTreeNodes.Values) {
@@ -327,4 +329,5 @@
           var origin = new Point(visualNode.X + visualNode.Width / 2, visualNode.Y + visualNode.Height);
           var target = new Point(visualSubtree.X + visualSubtree.Width / 2, visualSubtree.Y);
+          graphics.Clip = new Region(new Rectangle(Math.Min(origin.X, target.X), origin.Y, Math.Max(origin.X, target.X), target.Y));
           using (var linePen = new Pen(visualLine.LineColor)) {
             linePen.DashStyle = visualLine.DashStyle;
@@ -378,6 +381,5 @@
       Image image = new Bitmap(Width, Height);
       using (Graphics g = Graphics.FromImage(image)) {
-        int height = this.Height / tree.Depth;
-        DrawFunctionTree(tree, g, 0, 0, Width, height);
+        DrawFunctionTree(tree, g, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
       }
       image.Save(filename);
@@ -386,12 +388,11 @@
     public void SaveImageAsEmf(string filename) {
       if (tree == null) return;
-      using (var graphics = Graphics.FromImage(image)) {
-        var rectangle = new Rectangle(0, 0, image.Width, image.Height);
-        using (var metafile = new Metafile(filename, graphics.GetHdc(), rectangle, MetafileFrameUnit.Pixel, EmfType.EmfPlusDual)) {
-          graphics.ReleaseHdc();
-          using (var g = Graphics.FromImage(metafile)) {
-            DrawFunctionTree(tree, g, 0, 0, image.Width, image.Height);
+      using (Graphics g = CreateGraphics()) {
+        using (Metafile file = new Metafile(filename, g.GetHdc())) {
+          using (Graphics emfFile = Graphics.FromImage(file)) {
+            DrawFunctionTree(tree, emfFile, preferredNodeWidth, preferredNodeHeight, minHorizontalDistance, minVerticalDistance);
           }
         }
+        g.ReleaseHdc();
       }
     }
