diff --git a/templates/views-style-matrixtable-view-matrixtable.html.twig b/templates/views-style-matrixtable-view-matrixtable.html.twig
index aeebc923c62caf8c29c59e58cc017f8439a2de61..dd2b09fb6c7441750daeab3b97a02bc99cf81894 100644
--- a/templates/views-style-matrixtable-view-matrixtable.html.twig
+++ b/templates/views-style-matrixtable-view-matrixtable.html.twig
@@ -86,7 +86,9 @@
       {% endfor %}
       {% endfor %}
 
+      {% if matrix_row_total_names | length > 1 %}
       <th colspan="{{ matrix_row_total_names | length }}"> &nbsp; </th>
+      {% endif %}
     </tr>
     {% endif %}
   </thead>
@@ -99,12 +101,12 @@
     {% endfor %}
 
     {% for column in matrix_column_values %}
-    {% if matrix_values[row_nbr][column] | length == matrix_column_values | length %}
+    {% if matrix_values[row_nbr][column] | length == matrix_value_names | length %}
     {% for val in matrix_values[row_nbr][column] %}
     <td>{{ val | raw }}</td>
     {% endfor %}
     {% else %}
-    {% for val in matrix_column_values %}
+    {% for val in matrix_value_names %}
     <td> </td>
     {% endfor %}  
     {% endif %}