1

My question is smiliar to Creating a matrix with column or row vectors as arguments: I would like to typeset a matrix by indicating just its column vectors.

However the answers in the linked questions suggest things like

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\[
\begin{pmatrix}
    \vert & \vert \\
    v_1   & v_2   \\
    \vert & \vert
\end{pmatrix}
\]

\end{document}

The downside to this is that the matrix now is three rows high. I would like to have a solution that looks nice next to a 2x2 matrix. I then tried

\begin{pmatrix}
   \shortmid  & \shortmid \\[-1ex]
    v_1       & v_2   \\[-1ex]
    \shortmid & \shortmid
\end{pmatrix}

which is better, but not good. Also, it is absolutely not suitable for regular use, as it is basically just an ad-hoc solution.

5
  • What if you replace \vert with \phantom{}?
    – Cragfelt
    Commented Nov 4, 2019 at 15:01
  • I would like to have some sort of vertical bar in order to make it very clear that we are talking about entire columns. Commented Nov 4, 2019 at 15:09
  • If you use a notation where column vectors have a different appearance , like \textbf{v}_1 then you won't need to pad out columns. Commented Nov 4, 2019 at 15:14
  • Use [-0.5ex] as spacing parameter. It looks more centralized.
    – Cragfelt
    Commented Nov 4, 2019 at 15:28
  • @JohnKormylo Yes and no. For me as a mathematician, even the notation (v_1,v_2) is crystal clear. The text is for students who are just getting familiar with vectors and matrices. For them, this small visual guidance might help a lot. Commented Nov 4, 2019 at 21:16

1 Answer 1

2

This overlaps the text with two centered \rules. I threw in a 1pt gap at the top and bottom of the text.

\documentclass{article}
\usepackage{amsmath}

\newcommand{\spike}[2]% #1 = size of spike, #2 = centered text
{\bgroup
  \sbox0{#2}%
  \rlap{\usebox0}%
  \hspace{0.5\wd0}%
  \makebox[0pt][c]{\rule[\dimexpr \ht0+1pt]{0.5pt}{#1}}% top spike
  \makebox[0pt][c]{\rule[\dimexpr -\dp0-#1-1pt]{0.5pt}{#1}}% bottom spike
  \hspace{0.5\wd0}%
\egroup}

\begin{document}

\[
\begin{pmatrix}
    \spike{5pt}{$v_1$}  & \spike{5pt}{$v_2$}
\end{pmatrix}
\]

\end{document}

demo

3
  • Very nice, thank you. I was experimenting with a \shortstack inside the matrix, but it did not work out. Your solution is easy to use and flexible. Commented Nov 5, 2019 at 9:17
  • FWIW, I changed the first line to \newcommand{\spike}[2][3pt] so that I do not have to indicate the length of the spike at every invocation. Commented Nov 5, 2019 at 9:54
  • I left it variable just to make it easier to experiment with. Commented Nov 5, 2019 at 16:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .