Note that you have extra space around your vector. You should probably using something like (pmatrix
is part of the amsmath
package)
\begin{pmatrix}a\\b\end{pmatrix}
The standard LaTeX \newcommand
provides a way to have a single optional argument.
\newcommand*\colvec[3][]{
\begin{pmatrix}\ifx\relax#1\relax\else#1\\\fi#2\\#3\end{pmatrix}
}
Note that you have to use \colvec[a]{b}{c}
if you want three elements or \colvec{a}{b}
if you want two.
Update
As per your request in the comments, here's one that takes any number of elements based on the number passed in the first argument.
\newcount\colveccount
\newcommand*\colvec[1]{
\global\colveccount#1
\begin{pmatrix}
\colvecnext
}
\def\colvecnext#1{
#1
\global\advance\colveccount-1
\ifnum\colveccount>0
\\
\expandafter\colvecnext
\else
\end{pmatrix}
\fi
}
You use it exactly as you wanted, \colvec{5}{a}{b}{c}{d}{e}
.
Fractions
I'd just use the normal \frac
or \tfrac
. For display style maths they still look the best. I would use \nicefrac
(or similar) only (if at all) in text maths.
Code
\documentclass{article}
\usepackage{amsmath}
\def\frstfrac{\frac{2}{\sqrt{2y+1}\sqrt{2 \pi}}} % just a shortcut
\begin{document}
\begin{align*}
&= \frstfrac \exp \left( -y - \frac{1}{2}\right) && \forall y \in \left[- \frac{1}{2}, \infty\right) \\
&= \frstfrac \cdot e^{ -y - \frac{1}{2}} && \forall y \in \left[-\tfrac{1}{2}, \infty\right) \\
&= \frstfrac \cdot e^{ - \left(y + \frac{1}{2}\right)} && \forall y \in \left[-\tfrac{1}{2}, \infty\right) \\
&= \frstfrac \cdot e^{\textstyle -\!\left(y + \frac{1}{2}\right)} && \forall y \in \left[-\tfrac{1}{2}, \infty\right) \\
&= \frstfrac \exp \left( -y - 1/2 \right) && \forall y \in \left[- 1/ 2 , \infty\right)
\end{align*}
\end{document}
Output
\smash
Also, consider using \sqrt{\smash[b]{2y+1}}\sqrt{\smash[b]{2 \pi}}
in your denominator for better roots.
To quote from the amsmath
documentation:
With the amsmath package \smash
has optional arguments t
and b
, because occasionally it is advantageous to be able to “smash” only the top or only the bottom of something while retaining the natural depth or height.
Compare:
Code
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation*}
\frac{2}{\sqrt{\smash[b]{2y+1}}\sqrt{\smash[b]{2 \pi}}} = \frac{2}{\sqrt{2y+1}\sqrt{2 \pi}}
\end{equation*}
\end{document}
Output
The top bar of the root is aligned different and even the lower point is not on equal heights.
LaTeX Companion
The LaTeX Companion has a very elaborated text about \smash
and its uses. The first two examples (licensed under the LPPL) are shown here. Take a close look at the root's lower end and the top bar.
Code
\documentclass{article}
\usepackage{amsmath}
\begin{document}
$ \sqrt{x} + \sqrt{y} + \sqrt{z} $ \par
$ \sqrt{x} + \sqrt{\mathstrut y} + \sqrt{z} $ \par
$ \sqrt{x} + \sqrt{\smash{y}} + \sqrt{z} $ \par
$ \sqrt{x} + \sqrt{\smash[b]{y}} + \sqrt{z} $
\[
\sqrt{ \frac{a+b}{ x_j } } \quad
\sqrt{ \frac{a+b}{ \smash{x_j }} } \quad
\sqrt{ \frac{a+b}{{}\smash{x_j }} } \quad
\sqrt{ \frac{a+b}{ \smash{x_j+b}} }
\]
\end{document}
Output
Best Answer
A TABstack allows the inter-row baselineskip to be specified, while still keeping the baselineskip uniform, which I find important for vector/matrix notation.