GeneralMatrix Alignment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
wintermute01
Posts: 6
Joined: Thu Apr 10, 2008 9:20 am

Matrix Alignment

Post by wintermute01 »

Hello all,

I need help in aligning some long math in a matrix. I have tried the array format and it still doesn't work. My margins are 1.25in all around and simply inputting them as is results in the equation going outside the page. Breaking the math up into sections makes it get treated as different elements and therefore go out of alignment.
Here's the tex code with the array setting ( I used "bmatrix" with similar results):

Code: Select all

\begin{equation}
e^{[\mathbf{M}]}=
\left[\begin{array}{c c}
\cosh((\sqrt{k^2 - \hat{\sigma}^2})z)+\frac{i\hat{\sigma}}{(\sqrt{k^2-\hat{\sigma}^2})} \sinh((\sqrt{k^2-\hat{\sigma}^2})z) & \frac{i k}{(\sqrt{k^2 - \hat{\sigma}^2})} \sinh((\sqrt{k^2 -\hat{\sigma}^2})z)\\
\frac{-i k}{(\sqrt{k^2 - \hat{\sigma}^2})} \sinh((\sqrt{k^2 -\hat{\sigma}^2})z) & \cosh((\sqrt{k^2 - \hat{\sigma}^2})z) + \frac{-i \hat{\sigma}}{(\sqrt{k^2 - \hat{\sigma}^2})} \sinh((\sqrt{k^2 -\hat{\sigma}^2})z)
\end{array}\right]
\end{equation}
Thanks!

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Matrix Alignment

Post by Juanjo »

My first tentative has been

Code: Select all

\begin{equation}
   e^{[\mathbf{M}]}=
   \begin{bmatrix}
      \cosh(z\sqrt{k^2 - \hat{\sigma}^2}) 
         +\frac{i\hat{\sigma}}{\sqrt{k^2-\hat{\sigma}^2}} \sinh(z\sqrt{k^2-\hat{\sigma}^2}) 
      & \frac{i k}{\sqrt{k^2 - \hat{\sigma}^2}} \sinh(z\sqrt{k^2 -\hat{\sigma}^2})  \\[3ex]
      \frac{-i k}{\sqrt{k^2 - \hat{\sigma}^2}} \sinh(z\sqrt{k^2 -\hat{\sigma}^2}) 
      & \cosh(z\sqrt{k^2 - \hat{\sigma}^2}) 
         + \frac{-i \hat{\sigma}}{\sqrt{k^2 - \hat{\sigma}^2}} \sinh(z\sqrt{k^2 -\hat{\sigma}^2})
   \end{bmatrix}
\end{equation}
But I wonder if it is absolutely neccesary to keep the square root in the above expression. So why not introduce a new notation, say $\mu=\sqrt{k^2 - \hat{\sigma}^2}$ ? In this way, the matrix fits easily in a page:

Code: Select all

\begin{equation}
   e^{[\mathbf{M}]}=
   \begin{bmatrix}
      \cosh(\mu z) +\frac{i\hat{\sigma}}{\mu} \sinh(\mu z) 
      & \frac{i k}{\mu} \sinh(\mu z)  \\[3ex]
      \frac{-i k}{\mu} \sinh(\mu z) 
      & \cosh(\mu z) + \frac{-i \hat{\sigma}}{\mu} \sinh(\mu z)
   \end{bmatrix}
\end{equation}
Of course, I assume you are using the amsmath package.
balf
Posts: 158
Joined: Sat Jan 12, 2008 1:11 am

Re: Matrix Alignment

Post by balf »

I propose this code:
\setlength{\arraycolsep}{-6pt}\renewcommand{\arraystretch}{1.5}
\begin{multline}
e^{[\mathbf{M}]}=\\
\begin{medsize}
\left[\begin{matrix} \cosh(\sqrt{k^2 -
\hat{\sigma}^2}z)+\dfrac{i\hat{\sigma}}{\sqrt{k^2-\hat{\sigma}^2}}
\sinh(\sqrt{k^2-\hat{\sigma}^2}z)
& \dfrac{i k}{\sqrt{k^2 - \hat{\sigma}^2}} \sinh(\sqrt{k^2 -\hat{\sigma}^2}z)\\
\dfrac{-i k}{\sqrt{k^2 - \hat{\sigma}^2}} \sinh(\sqrt{k^2 -\hat{\sigma}^2}z) & \cosh(\sqrt{k^2 -
\hat{\sigma}^2}z) + \dfrac{-i \hat{\sigma}}{\sqrt{k^2 - \hat{\sigma}^2}} \sinh(\sqrt{k^2
-\hat{\sigma}^2}z)
\end{matrix}\right]
\end{medsize}
\end{multline}

As you can see I suppressed some unnecessary (in my opinion) parentheses. You also can slightly change the margin. You need to load the nncmath packaage (from the ncctools bundle), which defines a series of useful medium-size commands.

Best regards,
B.A.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Matrix Alignment

Post by localghost »

The problem could be solved by changing the character size in the coulmns of the array with help of the array package.

Code: Select all

\documentclass[BCOR13mm,DIV15]{scrartcl}
\usepackage{amsmath}
\usepackage{array}

\begin{document}
  \begin{equation}
    e^{[\boldsymbol{M}]}=
    \left[
    \begin{array}{>{\scriptstyle}c>{\scriptstyle}c}
      \cosh((\sqrt{k^2 - \hat{\sigma}^2})z)+\frac{i\hat{\sigma}}{(\sqrt{k^2-\hat{\sigma}^2})} \sinh((\sqrt{k^2-\hat{\sigma}^2})z) & \frac{i k}{(\sqrt{k^2 - \hat{\sigma}^2})} \sinh((\sqrt{k^2 -\hat{\sigma}^2})z) \\
      \frac{-i k}{(\sqrt{k^2 - \hat{\sigma}^2})} \sinh((\sqrt{k^2 -\hat{\sigma}^2})z) & \cosh((\sqrt{k^2 - \hat{\sigma}^2})z) + \frac{-i \hat{\sigma}}{(\sqrt{k^2 - \hat{\sigma}^2})} \sinh((\sqrt{k^2 -\hat{\sigma}^2})z)
    \end{array}
    \right]
  \end{equation}
\end{document}

Best regards
Thorsten¹
Post Reply