11

Is there a way to add a vertical line (equal sign) to an augmented bmatrix (4x4) WITHOUT using array? Any help provided would be greatly appreciated.

Werner
  • 603,163
TechEng
  • 111
  • 1
    Welcome to TeX.SE. Could you post some code, or at least a scan of a hand-drawn sketch of what you're looking to achieve? – Mico Mar 15 '16 at 21:31
  • @Mico: See the screenshot below from Steven, that is what I am trying to achieve but because I am using an application that does not support the use of array, I cannot use array to achieve it. – TechEng Mar 17 '16 at 14:25

4 Answers4

18

No, you have to use array, because the amsmath matrix environments don't provide for specifying rules.

\left[\begin{array}{@{}ccc|c@{}}
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4 \\
1 & 2 & 3 & 4
\end{array}\right]

The trick for emulating bmatrix (or pmatrix) is having @{} at both ends.

egreg
  • 1,121,712
  • Can you elaborate on what @{} means? – Eric Feb 15 '17 at 10:18
  • 1
    @Eric “Don't add the usual padding” – egreg Feb 15 '17 at 10:21
  • This still doesn't quite work for me. The one on the left uses bmatrix, the other {array}{@{}c@{}}. \hline seems to behave differently in the two cases – Eric Feb 15 '17 at 10:24
  • You actually want \left[\hskip -\arraycolsep ... \hskip -\arraycolsep\right], and to omit the @{} (determined by looking at amsmath.sty) – Eric Feb 15 '17 at 10:27
  • @Eric No, why should I? Do you doubt I know the code in amsmath? It's there in order to solve a very different problem. Of course, \hline was not requested. Otherwise, yes, the code like in amsmath can help. But that's partitioned matrices, there are questions about them on the site. – egreg Feb 15 '17 at 10:57
  • "No, why should I?" - because that is how you exactly emulate bmatrix. @{} is just an approximation. But in this case, you're right - what you have is sufficient. And no, the link was not for your benefit, but for any passers by :) – Eric Feb 15 '17 at 11:40
14

Here I use bmatrix, but have created \aug to be a vertical strut that can be placed between columns.

\documentclass{article}
\usepackage{amsmath}
\newcommand\aug{\fboxsep=-\fboxrule\!\!\!\fbox{\strut}\!\!\!}
\begin{document}
\[
\begin{bmatrix}
1 & 2 & 3 &\aug& 4 \\
1 & 2 & 3 &\aug& 4 \\
1 & 2 & 3 &\aug& 4 \\
1 & 2 & 3 &\aug& 4
\end{bmatrix}
\]
\end{document}

enter image description here

  • Thank you for responding but the application I am using does not support \aug either. There is not a complete and current list of the items supported by the application so I am going by trial and error. – TechEng Mar 17 '16 at 14:27
  • @TechEng Too bad. I gather you are unable to add LaTeX \newcommands to your existing application? – Steven B. Segletes Mar 17 '16 at 14:34
  • No, I am not. It is very limited. I can get the matrix using \begin{bmatrix} x & x & x & x\ \end{bmartix}, I just have not found a way to add the vertical line. – TechEng Mar 18 '16 at 16:43
  • @TechEng, Could you use \def\aug instead of \newcommand\aug? – Steven B. Segletes Mar 18 '16 at 16:45
  • No, \def\aug does not work either. It is very limited in what will work. I can make it work graphically by adding an image on top but I was hoping to get the equation to work by itself. I appreciate your time. I will just keep trying other things. – TechEng Mar 21 '16 at 14:44
  • @StevenB.Segletes, how can we port \aug to use with bsmallmatrix? – Ashirwad Apr 05 '20 at 19:14
  • @Ashirwad Maybe this: \newcommand\aug{\fboxsep=-\fboxrule\!\smash{\fbox{\scriptsize\mathstrut}}\!} – Steven B. Segletes Apr 05 '20 at 20:15
  • @StevenB.Segletes, it doesn't seem to work quite right. I have put your code on Overleaf, so you can try making changes here: https://www.overleaf.com/2572135168vrgkpzyygkzg and post the workable answer. – Ashirwad Apr 07 '20 at 02:11
  • @StevenB.Segletes, my bad, I didn't load the mathtools package in the preamble! It now works fine with bsmallmatrix, but now I see gaps between vertical struts in bmatrix! So, you may still want to check the link. :D Sorry for the confusion. – Ashirwad Apr 07 '20 at 02:18
  • @Ashirwad I do not get the gap you speak of, but you could always replace the \fbox with an explicit \rule in the manner of \newcommand\aug{\!\smash{\rule[-1pt]{.7pt}{7pt}}\!}, adjusting the rule values if needed. – Steven B. Segletes Apr 07 '20 at 02:26
  • Ok. I am sharing the read-only link. It won't ask you to log in: https://www.overleaf.com/project/5e8bde42ce7d6a0001126d0c I see it here! But anyways, I will try out your recommendation. – Ashirwad Apr 07 '20 at 02:31
9

For those who may still be searching for an answer. You can actually make an augmented matrix with two matrices inside delimiters of your choice:

\left[
  \begin{matrix}
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3 \\
    1 & 2 & 3 \\
  \end{matrix}
  \left|
    \,
    \begin{matrix}
      4  \\
      4  \\
      4  \\
      4  \\
    \end{matrix}
  \right.
\right]

This code produces a matrix like this:
Matrix example

You can modify space between delimiters by adding \, or other spacers.

Kartearis
  • 301
  • 4
    Not my preferred way, but at least it's easy to input. The \left| should better be \;\middle|\; (removing \right.). – egreg Mar 28 '20 at 21:33
  • +1 searching for a solution that works on mac Pages since forever and only this answer works – KMC Jan 09 '22 at 03:31
  • This has the added niceness of aligning perfectly with the definition of an augmented matrix $\left(A;\middle|;B\right)$ of $A$ and $B.$ – Allawonder Sep 07 '23 at 08:29
1

Using the package spalign you can get the answer faster with the command \spalignaugmat{}. Here within of this command the blank spaces between the elements of the matrix are important.

\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{spalign}
\begin{document}
\[ \spalignaugmat{1 2 3 4; 1 2 3 4; 1 2 3 4; 1 2 3 4;} \]
\end{document}

enter image description here

Sebastiano
  • 54,118