diff --git a/lam/lib/html.inc b/lam/lib/html.inc
index 25729a9e..3665971e 100644
--- a/lam/lib/html.inc
+++ b/lam/lib/html.inc
@@ -230,6 +230,24 @@ class htmlTable extends htmlElement {
if (is_null($table) || !($table instanceof htmlTable)) {
return;
}
+ // remove obsolete new lines at the end
+ if ($table->elements[sizeof($table->elements) - 1] == htmlTable::newLine) {
+ unset($table->elements[sizeof($table->elements) - 1]);
+ }
+ // close last row of other table if needed
+ if ($table->rowOpen) {
+ $table->elements[] = "\n";
+ }
+ // close last own row if needed
+ if ($this->rowOpen) {
+ if ($this->elements[sizeof($this->elements) - 1] == htmlTable::newLine) {
+ unset($this->elements[sizeof($this->elements) - 1]);
+ }
+ else {
+ $this->elements[] = "\n";
+ }
+ $this->rowOpen = false;
+ }
$this->elements = array_merge($this->elements, $table->elements);
}