Repository: Qiskit/qiskit

Issue:
Statevector drawer - `state_to_latex`'s max_size parameter cause unintended rounding
### Environment

- **Qiskit Terra version**: 0.22.3
- **Python version**: 3.10.8
- **Operating system**: Windows 10 22H2


### What is happening?

When I try to render the following state -
```py
sv = Statevector(
    [
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 - 0.35355339j,
        0.0 + 0.35355339j,
        0.0 + 0.35355339j,
        0.0 - 0.35355339j,
    ],
    dims=(2, 2, 2, 2)
)
```
using `sv.draw('latex', max_size=5)`
I get the following latext output with the coefficient round to 5 decimal point.
![未命名](https://user-images.githubusercontent.com/60516263/208237126-8b132bc8-3d7e-44db-aa4a-fe7e6e0c6459.png)
The arg `max_size=5` should only affect "Maximum number of non-zero terms in the expression", but also affects "Number of decimal places to round to".

### How can we reproduce the issue?

Code to reproduce the issue -
```py
sv = Statevector(
    [
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.35355339 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 + 0.0j,
        0.0 - 0.35355339j,
        0.0 + 0.35355339j,
        0.0 + 0.35355339j,
        0.0 - 0.35355339j,
    ],
    dims=(2, 2, 2, 2)
)
sv.draw("latex", max_size=5)
```

### What should happen?

Expected output should be like this :
![未命名](https://user-images.githubusercontent.com/60516263/208237099-011abb74-0b37-4e10-ae6c-8cf925798f34.png)


### Any suggestions?

In `state_visualization.py`, inside function `_state_to_latex_ket`, at line 1330、1336、1339.
When calling `np.around()` and `numbers_to_latex_terms()`, shouldn't use `max_size` as an argument to the parameter `decimals`.
https://github.com/Qiskit/qiskit-terra/blob/dd7f9390cf076f9545fa6086de486f2c06764ea5/qiskit/visualization/state_visualization.py#L1330-L1339


Discussion:

Resolving patch:
diff --git a/qiskit/visualization/state_visualization.py b/qiskit/visualization/state_visualization.py
--- a/qiskit/visualization/state_visualization.py
+++ b/qiskit/visualization/state_visualization.py
@@ -1361,7 +1361,9 @@ def _numbers_to_latex_terms(numbers: List[complex], decimals: int = 10) -> List[
     return terms
 
 
-def _state_to_latex_ket(data: List[complex], max_size: int = 12, prefix: str = "") -> str:
+def _state_to_latex_ket(
+    data: List[complex], max_size: int = 12, prefix: str = "", decimals: int = 10
+) -> str:
     """Convert state vector to latex representation
 
     Args:
@@ -1369,6 +1371,7 @@ def _state_to_latex_ket(data: List[complex], max_size: int = 12, prefix: str = "
         max_size: Maximum number of non-zero terms in the expression. If the number of
                  non-zero terms is larger than the max_size, then the representation is truncated.
         prefix: Latex string to be prepended to the latex, intended for labels.
+        decimals: Number of decimal places to round to (default: 10).
 
     Returns:
         String with LaTeX representation of the state vector
@@ -1378,16 +1381,16 @@ def _state_to_latex_ket(data: List[complex], max_size: int = 12, prefix: str = "
     def ket_name(i):
         return bin(i)[2:].zfill(num)
 
-    data = np.around(data, max_size)
+    data = np.around(data, decimals)
     nonzero_indices = np.where(data != 0)[0].tolist()
     if len(nonzero_indices) > max_size:
         nonzero_indices = (
             nonzero_indices[: max_size // 2] + [0] + nonzero_indices[-max_size // 2 + 1 :]
         )
-        latex_terms = _numbers_to_latex_terms(data[nonzero_indices], max_size)
+        latex_terms = _numbers_to_latex_terms(data[nonzero_indices], decimals)
         nonzero_indices[max_size // 2] = None
     else:
-        latex_terms = _numbers_to_latex_terms(data[nonzero_indices], max_size)
+        latex_terms = _numbers_to_latex_terms(data[nonzero_indices], decimals)
 
     latex_str = ""
     for idx, ket_idx in enumerate(nonzero_indices):


Test patch:
diff --git a/test/python/quantum_info/states/test_statevector.py b/test/python/quantum_info/states/test_statevector.py
--- a/test/python/quantum_info/states/test_statevector.py
+++ b/test/python/quantum_info/states/test_statevector.py
@@ -1263,6 +1263,60 @@ def test_state_to_latex_for_large_sparse_statevector(self):
         latex_representation = state_to_latex(sv)
         self.assertEqual(latex_representation, " |000000000000000\\rangle")
 
+    def test_state_to_latex_with_max_size_limit(self):
+        """Test limit the maximum number of non-zero terms in the expression"""
+        sv = Statevector(
+            [
+                0.35355339 + 0.0j,
+                0.35355339 + 0.0j,
+                0.35355339 + 0.0j,
+                0.35355339 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 - 0.35355339j,
+                0.0 + 0.35355339j,
+                0.0 + 0.35355339j,
+                0.0 - 0.35355339j,
+            ],
+            dims=(2, 2, 2, 2),
+        )
+        latex_representation = state_to_latex(sv, max_size=5)
+        self.assertEqual(
+            latex_representation,
+            "\\frac{\\sqrt{2}}{4} |0000\\rangle+"
+            "\\frac{\\sqrt{2}}{4} |0001\\rangle + "
+            "\\ldots +"
+            "\\frac{\\sqrt{2} i}{4} |1110\\rangle- "
+            "\\frac{\\sqrt{2} i}{4} |1111\\rangle",
+        )
+
+    def test_state_to_latex_with_decimals_round(self):
+        """Test rounding of decimal places in the expression"""
+        sv = Statevector(
+            [
+                0.35355339 + 0.0j,
+                0.35355339 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 + 0.0j,
+                0.0 - 0.35355339j,
+                0.0 + 0.35355339j,
+            ],
+            dims=(2, 2, 2),
+        )
+        latex_representation = state_to_latex(sv, decimals=3)
+        self.assertEqual(
+            latex_representation,
+            "0.354 |000\\rangle+0.354 |001\\rangle- 0.354 i |110\\rangle+0.354 i |111\\rangle",
+        )
+
     def test_number_to_latex_terms(self):
         """Test conversions of complex numbers to latex terms"""