LaTeX forum ⇒ Math & ScienceInline Column Vectors

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

Inline Column Vectors

Postby georgefrost123 » Mon Mar 08, 2010 11:53 pm

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:

  1. \newcommand{\tvect}[3]{ \begin{pmatrix} #1 \\ #2 \\ #3 \end{pmatrix} }
  2. ...
  3. $\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

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

Postby gmedina » Tue Mar 09, 2010 2:21 am

Hi,

you could try using the smallmatrix environment:

  1. \documentclass{article}
  2. \usepackage{amsmath}
  3.  
  4. \newcommand{\tvect}[3]{%
  5. \ensuremath{\Bigl(\negthinspace\begin{smallmatrix}#1\\#2\\#3\end{smallmatrix}\Bigr)}}
  6.  
  7. \begin{document}
  8.  
  9. text text text text text text text text text text text text text text text text text text text
  10. 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
  11.  
  12. \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

Postby georgefrost123 » Tue Mar 09, 2010 6:19 pm

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
Location: Colombia

Postby gmedina » Tue Mar 09, 2010 8:54 pm

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:

  1. \documentclass{article}
  2. \usepackage{amsmath}
  3.  
  4. \makeatletter
  5. % smallmatrix with left alignment
  6. \newenvironment{lsmallmatrix}{\null\,\vcenter\bgroup
  7. \Let@\restore@math@cr\default@tag
  8. \baselineskip6\ex@ \lineskip1.5\ex@ \lineskiplimit\lineskip
  9. \ialign\bgroup$\m@th\scriptstyle##$\hfil&&\thickspace\hfil
  10. $\m@th\scriptstyle##$\hfil\crcr
  11. }{%
  12. \crcr\egroup\egroup\,%
  13. }
  14. % smallmatrix with right alignment
  15. \newenvironment{rsmallmatrix}{\null\,\vcenter\bgroup
  16. \Let@\restore@math@cr\default@tag
  17. \baselineskip6\ex@ \lineskip1.5\ex@ \lineskiplimit\lineskip
  18. \ialign\bgroup\hfil$\m@th\scriptstyle##$&&\thickspace\hfil
  19. $\m@th\scriptstyle##$\hfil\crcr
  20. }{%
  21. \crcr\egroup\egroup\,%
  22. }
  23. \makeatother
  24.  
  25. % 3x1 smallmatrix with left alignment
  26. \newcommand{\ltvect}[3]{%
  27. \ensuremath{\Bigl(\negthinspace\begin{lsmallmatrix}#1\\#2\\#3\end{lsmallmatrix}\Bigr)}}
  28.  
  29. % 3x1 smallmatrix with right alignment
  30. \newcommand{\rtvect}[3]{%
  31. \ensuremath{\Bigl(\negthinspace\begin{rsmallmatrix}#1\\#2\\#3\end{rsmallmatrix}\Bigr)}}
  32.  
  33. % 3x1 smallmatrix with centered entries
  34. \newcommand{\ctvect}[3]{%
  35. \ensuremath{\Bigl(\negthinspace\begin{smallmatrix}#1\\#2\\#3\end{smallmatrix}\Bigr)}}
  36.  
  37. \begin{document}
  38.  
  39. Example of a smallmatrix with left alignment
  40. $\begin{lsmallmatrix}
  41. 5\\-1000\\3\\2
  42. \end{lsmallmatrix}$
  43.  
  44. \vspace{1cm}
  45.  
  46. Example of a smallmatrix with right alignment
  47. $\begin{rsmallmatrix}
  48. 5\\-1000\\3\\2
  49. \end{rsmallmatrix}$
  50.  
  51. \vspace{1cm}
  52.  
  53. Example of a smallmatrix with centered entries
  54. $\begin{smallmatrix}
  55. 5\\-1000\\3\\2
  56. \end{smallmatrix}$
  57.  
  58. \vspace{1cm}
  59.  
  60.  
  61. % left alignment
  62. text text text text text text text text text text text text text text text text text text text
  63. 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
  64.  
  65. % right alignment
  66. text text text text text text text text text text text text text text text text text text text
  67. 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
  68.  
  69. % centered
  70. text text text text text text text text text text text text text text text text text text text
  71. 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
  72.  
  73. \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
Location: Colombia

Postby gmedina » Tue Sep 14, 2010 7:37 pm

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

  1. % smallmatrix with right alignment
  2. \newenvironment{rsmallmatrix}{\null\,\vcenter\bgroup
  3. \Let@\restore@math@cr\default@tag
  4. \baselineskip6\ex@ \lineskip1.5\ex@ \lineskiplimit\lineskip
  5. \ialign\bgroup\hfil$\m@th\scriptstyle##$&&\thickspace\hfil
  6. $\m@th\scriptstyle##$\crcr
  7. }{%
  8. \crcr\egroup\egroup\,%
  9. }
1,1,2,3,5,8,13,21,34,55,89,144,233,...

kamrul
Posts: 3
Joined: Wed Sep 01, 2010 9:12 am

Postby kamrul » Thu Oct 21, 2010 2:14 am

Thanks! great work.


Return to “Math & Science”

Who is online

Users browsing this forum: No registered users and 3 guests