Math & ScienceMathematical Objects of same Width

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Mathematical Objects of same Width

Post by Cham »

I defined three commutators, and I would like to display them with exactly the same size (width).

Here's a minimal compilable example :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage{amsmath}
\usepackage{tensor}
\newcommand*{\1}{\hspace{1pt}}

\begin{document}
  \begin{align}
    [\; \tensor{\partial}{_i}, \, \tensor{\xi}{_j} \,] &= -\, \tensor{\varepsilon}{_{ijk}} \; \tensor{\partial}{_k}, \\ \nonumber \\
    [\; \tensor{\partial}{_i}, \, \tensor{\xi}{_{\textsf{dS}}} \1] &= -\, \omega \; \tensor{\partial}{_i}, \\ \nonumber \\
    [\; \tensor{\xi}{_i}, \, \tensor{\xi}{_{\textsf{dS}}} \1] &= 0.
  \end{align}
\end{document}
Here's a preview :
commutators.jpg
commutators.jpg (12.19 KiB) Viewed 6927 times
Currently, the brackets (commutators) on the left don't have the same width. I tried adding some spaces here and there using \, and \; but the results aren't satisfying. Using \phantom doesn't help much either. For aesthetical reasons, the first and third commutators should have the same size as the second one.

Any suggestions ?

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Mathematical Objects of same Width

Post by localghost »

An {array} — packed into a new command — could be an option. A very basic approach would look like this.

Code: Select all

\documentclass[12pt]{article}
\usepackage[T1]{fontenc}
\usepackage{mathtools}    % loads »amsmath«
\usepackage{tensor}
\usepackage{array}

\newcommand{\commutator}[2]{%
  [%
  \begin{array}{
    @{}
    >{\centering $\displaystyle}p{1em}<{$}
    @{,}
    >{\centering $\displaystyle}p{1.5em}<{$}
    @{}
  }
    #1 & #2
  \end{array}%
  ]%
}

\begin{document}
  \begin{align}
    \commutator{\tensor{\partial}{_i}}{\tensor{\xi}{_j}} &= -\tensor{\varepsilon}{_{ijk}}\tensor{\partial}{_k}, \\[2\jot]
    \commutator{\tensor{\partial}{_i}}{\tensor{\xi}{_{\textsf{dS}}}} &= -\omega\tensor{\partial}{_i}, \\[2\jot]
    \commutator{\tensor{\xi}{_i}}{\tensor{\xi}{_{\textsf{dS}}}} &= 0.
  \end{align}
\end{document}
Needs perhaps some adjustment for the column width depending on the content. But this could be incorporated into the \commutator command.


Thorsten
Attachments
commutator.png
commutator.png (6.49 KiB) Viewed 6920 times
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Mathematical Objects of same Width

Post by Stefan Kottwitz »

Another suggestion:

Code: Select all

\newcommand{\commutator}[3][1.2em]{[ \makebox[#1]{$#2$} , \makebox[#1]{$#3$} ]}
It can be used like Thorsten's suggestion: \commutator{first arg}{second arg}

It additionally supports a width argument, in case your expressions would have a different width in different formulas but should be made to the same width in each case: \commutator[width]{first arg}{second arg}. I just set 1.2em to the default.

Stefan
LaTeX.org admin
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Mathematical Objects of same Width

Post by Cham »

Ok. I get the idea.

Thanks to both of you. :)
User avatar
Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Mathematical Objects of same Width

Post by Cham »

Stefan,

your solution is very nice. However, I think there is too much space just before the 'comma', so I changed your commutator definition to this (notice the \!,) :

Code: Select all

\newcommand{\commutator}[3][1.4em]{[ \makebox[#1]{$#2$} \!, \makebox[#1]{$#3$} ]}
It's working, but is this the right way to reduce the extra space before the comma ? I want to be sure not to interfere with the width definition of the whole thing.

EDIT : By the way, the command to use the commutator is like this :
\commutator[width]{first arg}{second arg}
not
\commutator[width]{first arg,second arg}

Here's a sample of the commutator command in action. Very nice, isn't ? 8-)
commutators.jpg
commutators.jpg (36.99 KiB) Viewed 6890 times
Post Reply