10

I have (another) question on typesetting inline row vectors. I'm using amsmath and mathtools. I'm aware of the smallmatrix environment. Unfortunately, the elements of the vector get scaled. This seems completely unnecessary to me. Also the bmatrix environment is not a solution for me, since the delimiters are larger than "normal" text brackets.

I'd like to have something more like

\documentclass{article}
\usepackage{amsmath}
\usepackage{mathtools}
\begin{document}
Text $[\,x^* \quad  y^*\,]^*$
instead of
$
\begin{bmatrix}
x^* & y^* 
\end{bmatrix}^*
or
\begin{bsmallmatrix}
x^* & y^* 
\end{bsmallmatrix}^*
$    

\end{document}

Is there a package that can handle this special case for an arbitrary number of elements in the row vector? enter image description here

3 Answers 3

9

I recommend a general solution so that you can change the behaviour later, apart from using a more clean input code. Here's one with expl3.

\documentclass{scrartcl}

\usepackage{xparse,mathtools}

\ExplSyntaxOn

\NewDocumentCommand \vect { s o m }
 {
  \IfBooleanTF {#1}
   { \vectaux*{#3} }
   { \IfValueTF {#2} { \vectaux[#2]{#3} } { \vectaux{#3} } }
  ^*
 }

\DeclarePairedDelimiterX \vectaux [1] {\lbrack} {\rbrack}
 { \, \dbacc_vect:n { #1 } \, }

\cs_new_protected:Npn \dbacc_vect:n #1
 {
  \seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
  \seq_use:Nn \l_tmpa_seq { \enspace }
 }
\ExplSyntaxOff

\begin{document}

Text
$\vect{x^*,y^*}$
instead of
$\begin{bsmallmatrix} x^* & y^* \end{bsmallmatrix}^*$

\end{document}

And you can input \vect{x,y,z,t,u,v}, or \vect*{\int,\sum,\prod} or \vect[\Big]{a,b,\frac{n}{z}}, etc. like any other delimiter from \DeclarePairedDelimiter. Substitute \enspace for any space you want.

enter image description here

Addition

In case what you want is to input \vect{x,y,z} and get [x^* y^* z^*]^* just change one command

\cs_new_protected:Npn \dbacc_vect:n #1
 {
  \seq_clear:N \l_tmpb_seq
  \seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
  \seq_map_inline:Nn \l_tmpa_seq { \seq_put_right:Nn \l_tmpb_seq { ##1^* } }
  \seq_use:Nn \l_tmpb_seq { \enspace }
 }
4
  • Thanks a lot. This seems really like a robust implementation. Is it possible to put a star on each element of a vector for the starred version?
    – dba
    Commented Sep 10, 2015 at 14:36
  • Instead of \enspace you could add any other spacing like \quad (which, in my opinion is too much), or even use matrixes like egreg solutions; and maybe even more useful would be to use \enspace\allowbreak so, for long vectors it would break across lines (except if you use the starred version \vect*{a,a,a,a,a,a,a,a}). In any case, the basic idea is to use a nice syntax, which, apart from clarity, gives you the power to change the behaviour later.
    – Manuel
    Commented Sep 10, 2015 at 15:35
  • My question was rather how to get stars on each element automatically. E.g. if I put ^* in here \seq_use:Nn \l_tmpa_seq { ^* \enspace }, this will not respect the last element
    – dba
    Commented Sep 11, 2015 at 8:22
  • How to get stars? That was definitely not clear. In any case, I will just update.
    – Manuel
    Commented Sep 11, 2015 at 9:28
7

My suggestion is to simply type

\begin{bmatrix} x^* & y^* \end{bmatrix}

perhaps with a proper definition like

\newcommand{\rvect}[1]{\begin{bmatrix} #1 \end{bmatrix}}

and inputting

\rvect{x^* & y^*}

If you consider the & a nuisance, you can use a comma separated list:

\documentclass{scrartcl}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\rvect}{m}
 {
  \seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
  \begin{bmatrix}
  \seq_use:Nn \l_tmpa_seq { & }
  \end{bmatrix}
 }
\ExplSyntaxOff

\begin{document}

Text
$\rvect{x^*,y^*}$

\end{document}

enter image description here

Alternative, with \DeclarePairedDelimiterX and matrix inside.

\documentclass{scrartcl}

\usepackage{xparse,mathtools}

\DeclarePairedDelimiterX{\rvect}[1]{[}{]}{\,\makervect{#1}\,}

\ExplSyntaxOn
\NewDocumentCommand{\makervect}{m}
 {
  \seq_set_split:Nnn \l_tmpa_seq { , } { #1 }
  \begin{matrix}
  \seq_use:Nn \l_tmpa_seq { & }
  \end{matrix}
 }
\ExplSyntaxOff

\begin{document}

Text
$\rvect{x^*,y^*}$

\end{document}

You can manually increase the size of the delimiters with the usual optional argument to \rvect.

enter image description here

10
  • Thanks. I should probably have mentioned this, the problem with bmatrix is that the delimiters take too much space. I do not want to blow up the space between text lines with inline formulas.
    – dba
    Commented Sep 10, 2015 at 14:35
  • @dbacc Do they? I'm not sure they do.
    – egreg
    Commented Sep 10, 2015 at 14:35
  • I edited my question and added a picture. This should show my problem.
    – dba
    Commented Sep 10, 2015 at 15:06
  • @dbacc No, you don't get that picture, with your code. Are you using setspace and increased interline space? This would explain the problem, and, in this case, it should be mentioned in the question, because it's very important information. Anyway, my second solution doesn't show the issue.
    – egreg
    Commented Sep 10, 2015 at 15:10
  • You're right. It's in my document where its getting that large Could not track it down to any package for now and no I'm not setting setspace or something similar. However, even in the snippet from my answer the brackets from bmatrix are larger
    – dba
    Commented Sep 10, 2015 at 15:15
0

It is quite late for the answer, but I would like to contribute another way for typesetting row vectors using the physics package. According to the package's documentation, you can use the \mqty (matrix quantity) macro (see page 7&8, it has a lot of examples). For our case, we just need to write

\mqty[X_1 & X_2 & \cdots X_n]

for a row vector.

enter image description here

Please notice that after declaring the \mqty environment, vector's elements are surrounded by the square brackets (you can also use different types of outer pairs here, like | |, ( ) or { }).

You must log in to answer this question.

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