Repository: Qiskit/qiskit

Issue:
cu1 and rzz do not display properly in text drawer when wide gate underneath
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Information

- **Qiskit Terra version**: master
- **Python version**: 3.8
- **Operating system**: Ubuntu 18.04

### What is the current behavior?

cu1 and rzz display params multiple times in the text drawer when there is a wide gate underneath in the same layer.

### Steps to reproduce the problem
```
from qiskit import QuantumCircuit
from numpy import pi

qc = QuantumCircuit(5)
qc.rzz(pi/2, 0, 1)
qc.cu1(pi/2, 2, 3)
qc.x(4, label='This is a really long X')
print(qc)

q_0: ─■─────────────────────────
      │zz(pi/2zz(pi/2zz(pi/2)   
q_1: ─■─────────────────────────
                                
q_2: ─────────■─────────────────
              │pi/pi/2          
q_3: ─────────■─────────────────
     ┌─────────────────────────┐
q_4: ┤ This is a really long X ├
     └─────────────────────────┘
```

### What is the expected behavior?



### Suggested solutions





Discussion:
Good catch!

Resolving patch:
diff --git a/qiskit/visualization/text.py b/qiskit/visualization/text.py
--- a/qiskit/visualization/text.py
+++ b/qiskit/visualization/text.py
@@ -1080,7 +1080,7 @@ def build_layers(self):
                     self._instruction_to_gate(instruction, layer)
 
                 layer.connections.append((connection_label, current_connections))
-                layer.connect_with("│")
+            layer.connect_with("│")
             layers.append(layer.full_layer)
 
         return layers


Test patch:
diff --git a/test/python/visualization/test_circuit_text_drawer.py b/test/python/visualization/test_circuit_text_drawer.py
--- a/test/python/visualization/test_circuit_text_drawer.py
+++ b/test/python/visualization/test_circuit_text_drawer.py
@@ -902,6 +902,38 @@ def test_label_on_controlled_gate(self):
 
         self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
 
+    def test_rzz_on_wide_layer(self):
+        """ Test a labeled gate (RZZ) in a wide layer.
+        See https://github.com/Qiskit/qiskit-terra/issues/4838"""
+        expected = '\n'.join(["                                               ",
+                              "q_0: |0>───────────────■───────────────────────",
+                              "                       │zz(pi/2)               ",
+                              "q_1: |0>───────────────■───────────────────────",
+                              "        ┌─────────────────────────────────────┐",
+                              "q_2: |0>┤ This is a really long long long box ├",
+                              "        └─────────────────────────────────────┘"])
+        circuit = QuantumCircuit(3)
+        circuit.rzz(pi / 2, 0, 1)
+        circuit.x(2, label='This is a really long long long box')
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
+    def test_cu1_on_wide_layer(self):
+        """ Test a labeled gate (CU1) in a wide layer.
+        See https://github.com/Qiskit/qiskit-terra/issues/4838"""
+        expected = '\n'.join(["                                               ",
+                              "q_0: |0>─────────────────■─────────────────────",
+                              "                         │pi/2                 ",
+                              "q_1: |0>─────────────────■─────────────────────",
+                              "        ┌─────────────────────────────────────┐",
+                              "q_2: |0>┤ This is a really long long long box ├",
+                              "        └─────────────────────────────────────┘"])
+        circuit = QuantumCircuit(3)
+        circuit.cu1(pi / 2, 0, 1)
+        circuit.x(2, label='This is a really long long long box')
+
+        self.assertEqual(str(_text_circuit_drawer(circuit)), expected)
+
 
 class TestTextDrawerMultiQGates(QiskitTestCase):
     """ Gates implying multiple qubits."""