Repository: Qiskit/qiskit

Issue:
bug in latex drawer barrier
<!-- ⚠️ If you do not respect this template, your issue will be closed -->
<!-- ⚠️ Make sure to browse the opened and closed issues -->

### Informations

- **Qiskit Terra version**:
- **Python version**:
- **Operating system**:

### What is the current behavior?
When drawing this circuit, the barrier on the last qubit is not respected. 
```python
from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit
from qiskit.tools.visualization import circuit_drawer
q = QuantumRegister(3, 'q')
c = ClassicalRegister(3, 'c')
circ = QuantumCircuit(q, c)
circ.x(q[0])
circ.x(q[1])
circ.barrier(q)
circ.measure(q, c)
circuit_drawer(circ, output='latex')
```

![image](https://user-images.githubusercontent.com/8622381/47267192-53fabd80-d50e-11e8-9325-7fb46a6eac27.png)

The `mpl` drawer works fine.

### Suggested solutions





Discussion:
Hmm, this one is gonna be a bit trickier to fix. The issue is the barrier isn't actually an element in the underlying xymatrix that qcircuit is building. So to fix this we'll have to iterate over the rows and somehow figure out that we need to insert a \qw at that column and move the \measure over. I'm not exactly sure how to do that though. 
is there an update on this. 
Is this for 0.7
Assuming there isn't an update, I could try and have a look at this. It seems like it is quite a bit more in depth than the other issues I've had a go at so far so not sure how long it will take me or whether I'll be even be able to do it! But it noone else is trying I'm happy to give it a go!
I have not had a chance to work on this (I moved it to in progress in the project by mistake) so there is no update on this. I wasn't going to wait on this for 0.7.

@charlesastaylor if you want to give it a try, go for it. I can give you help if you need it. I have a feeling it'll be annoying to fix though since we'll have to at least iterate over the circuit one more time at the end to figure out whether we'll need to space things out.
Just leaving a comment here that #1306 was a duplicate of this issue, but manifested itself differently by raising a `VisualizationError` with the error message: `Error during Latex building: invalid literal for int() with base 10: '1} \\\\barrier{1'` you can look at the closing for duplicate comment: https://github.com/Qiskit/qiskit-terra/issues/1306#issuecomment-441735166 for more details on why/how.

Resolving patch:
diff --git a/qiskit/tools/visualization/_latex.py b/qiskit/tools/visualization/_latex.py
--- a/qiskit/tools/visualization/_latex.py
+++ b/qiskit/tools/visualization/_latex.py
@@ -413,8 +413,28 @@ def _get_image_depth(self, aliases=None):
                     columns += 1
                     is_occupied = [False] * self.img_width
                     is_occupied[pos_1] = True
-            elif op['name'] == "barrier":
-                pass
+            elif op['name'] in ["barrier", 'snapshot', 'load', 'save',
+                                'noise']:
+                if self.plot_barriers:
+                    qarglist = op['qargs']
+                    indexes = [self._get_qubit_index(x) for x in qarglist]
+                    start_bit = self.qubit_list[min(indexes)]
+                    if aliases is not None:
+                        qarglist = map(lambda x: aliases[x], qarglist)
+                    start = self.img_regs[start_bit]
+                    span = len(op['qargs']) - 1
+                    for i in range(start, span + 1):
+                        if is_occupied[i] is False:
+                            is_occupied[i] = True
+                        else:
+                            columns += 1
+                            is_occupied = [False] * self.img_width
+                            for j in range(start, span + 1):
+                                is_occupied[j] = True
+                            break
+                    # update current column width
+                    if columns not in max_column_width:
+                        max_column_width[columns] = 0
             else:
                 raise _error.VisualizationError("bad node data")
         # every 3 characters is roughly one extra 'unit' of width in the cell
@@ -916,7 +936,16 @@ def _build_latex_array(self, aliases=None):
                         qarglist = map(lambda x: aliases[x], qarglist)
                     start = self.img_regs[start_bit]
                     span = len(op['qargs']) - 1
-                    self._latex[start][columns] += " \\barrier{" + str(
+                    for i in range(start, span + 1):
+                        if is_occupied[i] is False:
+                            is_occupied[i] = True
+                        else:
+                            columns += 1
+                            is_occupied = [False] * self.img_width
+                            for j in range(start, span + 1):
+                                is_occupied[j] = True
+                            break
+                    self._latex[start][columns] = "\\qw \\barrier{" + str(
                         span) + "}"
             else:
                 raise _error.VisualizationError("bad node data")


Test patch: