7

I would like to produce the following matrix : enter image description here:

My code is below which only produces the matrix without the additional column.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{equation*}
    \mathbf{H}=
    \begin{pmatrix}
        1 & 2 & 3 & 5\\
        1 & 1 & 4 & 2\\
        4 & 1 & 2 & 4
    \end{pmatrix}
   \end{equation*}
\end{document}
zdm
  • 667
  • 4
  • 11

4 Answers4

7

One possibility might be to employ blkarray.

\documentclass{article}
\usepackage{blkarray}
\usepackage{amsmath}
\begin{document}  
\[\begin{blockarray}{(>{\:}cccc<{\:})l}
       1 & 2 & 3 & 5 & 10\\
        1 & 1 & 4 & 2 & 10\\
        4 & 1 & 2 & 4 & 10 \\
\end{blockarray}\]
\end{document}

enter image description here

5

One possible option is just adding another matrix.

\documentclass{article}
\usepackage{amsmath}

\begin{document}
\begin{equation*}
    \mathbf{H}=
    \begin{pmatrix}
        1 & 2 & 3 & 5\\
        1 & 1 & 4 & 2\\
        4 & 1 & 2 & 4
    \end{pmatrix}
    \begin{matrix}
        10\\10\\10
    \end{matrix}
   \end{equation*}
\end{document}

enter image description here

AboAmmar
  • 46,352
  • 4
  • 58
  • 127
  • Your solution works in this special case where all matrix cells have the standard height. It doesn't work when the cells contain something like \frac{\frac12}3. – Roland Illig Apr 27 '19 at 13:34
  • Sure, LaTeX has many packages for dealing with cases with different complexities, but one should go for the simplest solution first, generalization has its cost! – AboAmmar Apr 27 '19 at 14:17
5

Considering that matrices are also arrays, I provide a version with basic LaTeX tools:

enter image description here

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[\mathbf{H}=\Bigg(
\begin{array}{cccc}
    1 & 2 & 3 & 5\\
    1 & 1 & 4 & 2\\
    4 & 1 & 2 & 4
\end{array}\Bigg)
\begin{array}{c}
    10\\
    10\\
    10
\end{array}
\]

\end{document}
Sebastiano
  • 54,118
4

EDIT after the advice of the 2019-10-24 of the author of nicematrix @F. Pantigny reported in the comment.

As another alternative you could add with appropriate modifications using the nicematrix package. For example using the environment {pNiceMatrix} with the option last-col=5.

You can see that you will have the same result as output.

enter image description here

\documentclass[12pt]{article}
\usepackage{nicematrix}
\begin{document}
\[\mathbf{H}= \begin{pNiceMatrix}[last-col=5]
1 & 2 & 3 & 5 & 10\\
 1 & 1 & 4 & 2 & 10\\
4 & 1 & 2 & 4 & 10\\
\end{pNiceMatrix}
\]
\end{document}
Sebastiano
  • 54,118
  • 1
    you can delete row with \phantom and than replace pNiceArrayRC with pNiceArrayC and you will obtain the same result :-) – Zarko May 02 '19 at 21:39
  • @Zarko Of course. :-) – Sebastiano May 02 '19 at 21:42
  • @Zarko Don you know the reason of my downvote? – Sebastiano May 03 '19 at 17:22
  • No, I don't know. Your answer not deserve this. Unfortunately I cant up-vote again :-(. – Zarko May 03 '19 at 19:29
  • @Zarko I am not very expert of LaTeX but I have understood, many times, because I receveid severals downvotes without an explanation. I am very interesting to increase my experience in LaTeX and I'm not interesting for votes. Thank you very much always. Bye. – Sebastiano May 03 '19 at 19:32
  • 1
    @Sebastino: You should update your answer because {pNiceArrayC} is now deprecated in the package nicematrix. You may use {pNiceArray} with the option last-col instead or even {pNiceMatrix} with the option last-col=5. – F. Pantigny Oct 24 '19 at 19:14
  • @F.Pantigny You're a friend :-) thanks. I think it's okay now. – Sebastiano Oct 24 '19 at 19:57