Math & ScienceInline Column Vectors

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
georgefrost123
Posts: 2
Joined: Mon Mar 08, 2010 11:49 pm

Inline Column Vectors

Post by georgefrost123 »

Hi,


I'm new both to LaTeX and to the forum - nice to meet you all! :D

I've been having a problem getting column vectors to display in a way that they don't interrupt the flow of the text. I have 3-vectors that I'd ideally like to display inline with minimal disruption to the line spacing above or below.

Currently I've been using:

Code: Select all

\newcommand{\tvect}[3]{ \begin{pmatrix} #1 \\ #2 \\ #3 \end{pmatrix} }
...
$\tvect{1}{2}{3}$
to define the 3-vector, but that's making a huge vector and messing up the flow of the text.

Any advice?


Thanks,
George

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Inline Column Vectors

Post by gmedina »

Hi,

you could try using the smallmatrix environment:

Code: Select all

\documentclass{article}
\usepackage{amsmath}

\newcommand{\tvect}[3]{%
  \ensuremath{\Bigl(\negthinspace\begin{smallmatrix}#1\\#2\\#3\end{smallmatrix}\Bigr)}}

\begin{document}

text text text text text text text text text text text text text text text text text text text 
text $\tvect{1}{2}{3}$ text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

\end{document} 
1,1,2,3,5,8,13,21,34,55,89,144,233,...
georgefrost123
Posts: 2
Joined: Mon Mar 08, 2010 11:49 pm

Inline Column Vectors

Post by georgefrost123 »

That's exactly what I was looking for, thanks! Didn't know the smallmatrix environment existed.

Is is possible to centralise (or right-align) the elements in the matrix?

Also, I'm guessing that \ensuremath{...} appends $s accordingly to prevent errors? Finally (sorry for the many questions!), does the \negthinspace ensure the left bracket sits properly alongside the column?


Thanks,

George
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Inline Column Vectors

Post by gmedina »

georgefrost123 wrote:Is is possible to centralise (or right-align) the elements in the matrix?
Yes, it is possible. The environment smallmatrix, by default, centers the entries. In the following code I defined two mew environments similar to smallmatrix: lsmallmatrix (left alignment for the entries) and rsmallmatrix (right alignment for the entries).

I used those (together with smallmatrix) to define new commands for 3x1 matrices with different alignment. The example shows the new environments and commands in action:

Code: Select all

\documentclass{article}
\usepackage{amsmath}

\makeatletter
% smallmatrix with left alignment
\newenvironment{lsmallmatrix}{\null\,\vcenter\bgroup
  \Let@\restore@math@cr\default@tag
  \baselineskip6\ex@ \lineskip1.5\ex@ \lineskiplimit\lineskip
  \ialign\bgroup$\m@th\scriptstyle##$\hfil&&\thickspace\hfil
  $\m@th\scriptstyle##$\hfil\crcr
}{%
  \crcr\egroup\egroup\,%
}
% smallmatrix with right alignment
\newenvironment{rsmallmatrix}{\null\,\vcenter\bgroup
  \Let@\restore@math@cr\default@tag
  \baselineskip6\ex@ \lineskip1.5\ex@ \lineskiplimit\lineskip
  \ialign\bgroup\hfil$\m@th\scriptstyle##$&&\thickspace\hfil
  $\m@th\scriptstyle##$\hfil\crcr
}{%
  \crcr\egroup\egroup\,%
}
\makeatother

% 3x1 smallmatrix with left alignment
\newcommand{\ltvect}[3]{%
  \ensuremath{\Bigl(\negthinspace\begin{lsmallmatrix}#1\\#2\\#3\end{lsmallmatrix}\Bigr)}}

% 3x1 smallmatrix with right alignment
\newcommand{\rtvect}[3]{%
  \ensuremath{\Bigl(\negthinspace\begin{rsmallmatrix}#1\\#2\\#3\end{rsmallmatrix}\Bigr)}}

% 3x1 smallmatrix with centered entries
\newcommand{\ctvect}[3]{%
  \ensuremath{\Bigl(\negthinspace\begin{smallmatrix}#1\\#2\\#3\end{smallmatrix}\Bigr)}}

\begin{document}

Example of a smallmatrix with left alignment
$\begin{lsmallmatrix}
  5\\-1000\\3\\2
\end{lsmallmatrix}$

\vspace{1cm}

Example of a smallmatrix with right alignment
$\begin{rsmallmatrix}
  5\\-1000\\3\\2
\end{rsmallmatrix}$

\vspace{1cm}

Example of a smallmatrix with centered entries
$\begin{smallmatrix}
  5\\-1000\\3\\2
\end{smallmatrix}$

\vspace{1cm}


% left alignment
text text text text text text text text text text text text text text text text text text text 
text $\ltvect{-100000}{2}{3}$ text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

% right alignment
text text text text text text text text text text text text text text text text text text text 
text $\rtvect{-100000}{2}{3}$ text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

% centered
text text text text text text text text text text text text text text text text text text text 
text $\ctvect{-100000}{2}{3}$ text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

\end{document}
georgefrost123 wrote:...Also, I'm guessing that \ensuremath{...} appends $s accordingly to prevent errors? Finally (sorry for the many questions!), does the \negthinspace ensure the left bracket sits properly alongside the column?..
Don't worry; you can ask as many questions as you wish.

\ensuremath is a LaTeX2e command that ensures that its argument is typeset always in math mode by enclosing it, if necessary, with $ signs.

\negthinspace, \negmedspace and \negthickspace are commands implemented by the amsmath package to produce negative horizontal spacing; their default value is 3mu, 4mu plus 2mu minus 4mu, and 5mu plus 5mu, respectively. Those commands can be used both in text and math mode.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Inline Column Vectors

Post by gmedina »

There was an extra \hfil command in the definition of rsmallmatrix; here's the corrected version:

Code: Select all

% smallmatrix with right alignment
\newenvironment{rsmallmatrix}{\null\,\vcenter\bgroup
  \Let@\restore@math@cr\default@tag
  \baselineskip6\ex@ \lineskip1.5\ex@ \lineskiplimit\lineskip
  \ialign\bgroup\hfil$\m@th\scriptstyle##$&&\thickspace\hfil
  $\m@th\scriptstyle##$\crcr
}{%
  \crcr\egroup\egroup\,%
}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
kamrul
Posts: 3
Joined: Wed Sep 01, 2010 9:12 am

Re: Inline Column Vectors

Post by kamrul »

Thanks! great work.
Post Reply