Math & ScienceVertical alignment of genfrac-derived command within parens

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
kpedro88
Posts: 6
Joined: Wed Aug 27, 2014 7:47 pm

Vertical alignment of genfrac-derived command within parens

Post by kpedro88 »

I was looking for ways to extend the \binom command to include more than 2 arguments. The formatting of \pmatrix was not satisfying for me, so I came up with a custom command based on \genfrac from amsmath:

Code: Select all

\newcommand\triplet[3]{\left(\genfrac{}{}{0pt}{0}{#1}{\genfrac{}{}{0pt}{0}{#2}{#3}}\right)}
I'm mostly satisfied with how this appears, except that the arguments are not quite vertically centered within the parentheses. Can anyone offer a way to make the arguments vertically centered?

I have attached an example showing \binom and my new command \triplet for comparison.

Code: Select all

\documentclass{article}
\usepackage{amsmath}
\begin{document}

\newcommand\triplet[3]{\left(\genfrac{}{}{0pt}{0}{#1}{\genfrac{}{}{0pt}{0}{#2}{#3}}\right)}

\begin{equation}
\binom{1/3}{-2/3}
\end{equation}

\begin{equation}
\triplet{2/3}{-1/3}{-4/3}
\end{equation}

\end{document}
Attachments
kpedroGenfrac.png
kpedroGenfrac.png (11.21 KiB) Viewed 6436 times
triplet.pdf
(31.47 KiB) Downloaded 342 times
Last edited by Johannes_B on Tue Sep 16, 2014 9:33 am, edited 1 time in total.

Recommended reading 2024:

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

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

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Vertical alignment of genfrac-derived command within parens

Post by Johannes_B »

I would use a different approach.

Code: Select all

\documentclass{article}
\usepackage{mathtools}
\begin{document}

\newcommand\tripler[4][c]{\left(%
	\begin{array}{@{}#1@{}}#2\\#3\\#4%
\end{array}%
\right)%
}

\begin{equation}
\binom{1/3}{-2/3}
\end{equation}

\begin{equation}
\tripler{2/3}{-1/3}{-4/3}
\end{equation}

\begin{equation}
\tripler[r]{2/3}{-1/3}{-4/3}
\end{equation}
\end{document}
Attachments
kpedroOutput.png
kpedroOutput.png (23.27 KiB) Viewed 6427 times
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
kpedro88
Posts: 6
Joined: Wed Aug 27, 2014 7:47 pm

Vertical alignment of genfrac-derived command within parens

Post by kpedro88 »

That's fantastic. Everything aligns perfectly. I'm actually going to replace \binom with the equivalent version of that command just for the alignment. Thanks so much!
Post Reply