Math & ScienceMatrix Column Spacing

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

Matrix Column Spacing

Post by Cham »

I have a 4 x 4 matrix which needs better spacings. Here's a compilable code :

Code: Select all

\documentclass[12pt,letterpaper]{article}
\usepackage[utf8]{inputenc}
\usepackage[french]{babel}
\usepackage{amsmath}
\usepackage{tensor}
\newcommand{\qvec}[1]{\boldsymbol{#1}}
\begin{document}
	\begin{equation}
		\frac{d}{d \theta} \!
		\left[ \begin{array}{c}
			\tensor{c}{_1} \\
			\tensor{c}{_2} \\
			\tensor{c}{_3} \\
			\tensor{c}{_4} \\
		\end{array} \right] =
		\left[ \begin{array}{cccc}
			0 & 0 & \tensor{\mathcal{J}}{_{\qvec{F}}} & 0 \\
			1 & 0 & 0 & 2 \tensor{\mathcal{I}}{_{\qvec{F}}} \\
			0 & 0 & 0& \tensor{\mathcal{J}}{_{\qvec{F}}} \\
			0 & 1 & 0 & 0
		\end{array} \right]\!\!
		\left[ \begin{array}{c}
			\tensor{c}{_1} \\
			\tensor{c}{_2} \\
			\tensor{c}{_3} \\
			\tensor{c}{_4} \\
		\end{array} \right]\!\!.
	\end{equation}
\end{document}
Currently, the columns in the 4 x 4 matrix aren't well balanced. How can I tell LaTeX to give the same spacing for each column (without changing the vectors on the left and on the right) ?

Here's a preview :
matrix.jpg
matrix.jpg (12.92 KiB) Viewed 19495 times
I could use the \phantom command and hack the matrix by hand, but I don't think this would be the correct way to do it.

Recommended reading 2024:

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

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

Cham
Posts: 937
Joined: Sat Apr 02, 2011 4:06 pm

Re: Matrix Column Spacing

Post by Cham »

No idea on this ?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

Matrix Column Spacing

Post by Stefan Kottwitz »

As you provided a nice compilable example, I gladly suggest a solution. I would use the array package, for defining a centered math column type of a adjustable width:

Code: Select all

\usepackage{array}
\newcolumntype{C}[1]{>{\centering\arraybackslash$}p{#1}<{$}}
In the code, you could specify a bunch of columns of equal width with the * syntax of the array package:

Code: Select all

\begin{array}{*4{C{2em}}}
You still have once to specify a width for all columns. However, the definition could be changed to take the widest cell entry as argument and adjusting the columns matching to it, using \settowidth.

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

Re: Matrix Column Spacing

Post by Cham »

Wow !

Thanks Stefan, it works like a charm !
Post Reply