How can matrices be written in Latex with or without vertical lines?

In summary, to write a matrix in Latex, you can use the \begin{matrix} \end{matrix} environment and separate columns with & and rows with \\.To adjust the size of a matrix, you can use \left( \right) or \big( \big) commands, or choose from different bracket types using \left[ \right], \big[ \big], \left\{ \right\}, or \big\{ \big\}.To add labels or captions to a matrix, use the \label{} and \caption{} commands within and outside of the \begin{matrix} environment.To highlight specific columns or rows, use the \array command and \hline to add horizontal lines
  • #1
basty
95
0
How do you write a matrix such as below image in Latex, in this forum?

Matrix.png
 
Physics news on Phys.org
  • #2
  • #3
Normally, the easiest way to write a matrix is to use the pmatrix environment:
Code:
\begin{pmatrix}
2 & 6 & 1 \\ 1 & 2 & -1 \\ 5 & 7 & -4
\end{pmatrix}
$$
\begin{pmatrix}
2 & 6 & 1 \\ 1 & 2 & -1 \\ 5 & 7 & -4
\end{pmatrix}
$$

If you need the vertical line, you have to do the matrix "by hand," and it requires a bit more work:
Code:
\left(
\begin{array}{rrr|r}
2 & 6 & 1 & 7 \\ 1 & 2 & -1 & -1 \\ 5 & 7 & -4 & 9
\end{array}
\right)
$$
\left(
\begin{array}{rrr|r}
2 & 6 & 1 & 7 \\ 1 & 2 & -1 & -1 \\ 5 & 7 & -4 & 9
\end{array}
\right)
$$
 
  • Like
Likes Greg Bernhardt

1. How do I write a matrix in Latex?

To write a matrix in Latex, you can use the \begin{matrix} \end{matrix} environment. Within this environment, you can use the & symbol to separate the columns and \\ to separate the rows. For example, \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} will display a 3x3 matrix with the numbers 1-9.

2. How do I adjust the size of a matrix in Latex?

To adjust the size of a matrix in Latex, you can use the \left( \right) or \big( \big) commands. For example, \left( \begin{matrix} 1 & 2 \\ 3 & 4 \end{matrix} \right) will display a matrix surrounded by large parentheses, while \big( \begin{matrix} 1 & 2 \\ 3 & 4 \end{matrix} \big) will display a matrix surrounded by smaller parentheses. You can also use \left[ \right] or \big[ \big] for square brackets, or \left\{ \right\} or \big\{ \big\} for curly brackets.

3. How do I write a matrix with brackets in Latex?

To write a matrix with brackets in Latex, you can use the \begin{bmatrix} \end{bmatrix} environment. This will automatically add brackets around your matrix, similar to \left[ \right] or \big[ \big] as mentioned in the previous question.

4. Can I add labels or captions to a matrix in Latex?

Yes, you can add labels or captions to a matrix in Latex by using the \label{} and \caption{} commands. First, you need to add a label within the \begin{matrix} environment, for example \begin{matrix} 1 & 2 \\ 3 & 4 \label{mylabel}\end{matrix}. Then, you can add a caption outside of the matrix environment, for example \caption{My Matrix} \label{mycaption}. You can then refer to the matrix or caption by using \ref{mylabel} or \ref{mycaption} in your document.

5. How do I write a matrix with specific columns or rows highlighted in Latex?

To write a matrix with specific columns or rows highlighted in Latex, you can use the \array command. For example, \array\{ c c | c \} \begin{matrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{matrix} will create a matrix with the first two columns separated from the third column by a vertical line. You can also use \hline to add a horizontal line between rows. For more advanced formatting, you can use the nicematrix package.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
827
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
901
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
782
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
328
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
7
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
966
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
2K
Back
Top