13

I am having some difficulty getting this to display properly.

 \begin{equation}
{\bf H} = -{\bf \mu} \cdot {\bf B} = - \gamma B_o {\bf S}_z = -\frac{\gamma B_o\hbar}{2} 
\begin{bmatrix} 1&0\\0&-1 \end{bmatrix}.
\end{equation}

Which appears as,

Ugly looking equation

I would like the matrix height to be consistant with the rest of the equation.

2
  • 2
    Welcome to TeX.SX! Judging from the picture you seem to be using some setspace command or \linespread for increasing the leading. Can you confirm? By the way, avoid {\bf H} that should be \mathbf{H}.
    – egreg
    Oct 8, 2013 at 17:29
  • Yes I am using setspace throughout my document. Thank you for the \mathbf{} tip!
    – Shinobii
    Oct 8, 2013 at 17:31

4 Answers 4

9
\documentclass{article}
\usepackage{amsmath}
\usepackage[nodisplayskipstretch]{setspace}
\doublespacing
\everydisplay\expandafter{\the\everydisplay\setstretch{1}}% return to singlespacing

\begin{document}
\begin{equation}
\mathbf{H} = -\mathbf\mu \cdot \mathbf{B} = -\gamma B_o \mathbf{S}_z = -\frac{\gamma B_o\hbar}{2} 
\begin{bmatrix} 1&0\\0&-1 \end{bmatrix}.
\end{equation}

\end{document} 
2
  • 1
    You may want to use \boldsymbol{\mu} instead of \mathbf{\mu}.
    – Mico
    Oct 8, 2013 at 17:55
  • 4
    You get Command \normalsize invalid in math mode at every display, which could be annoying.
    – egreg
    Oct 8, 2013 at 18:04
11

I'd modify the \env@matrix command, on which all the matrix constructions are built;

\documentclass{article}

\usepackage{amsmath,bm}
\usepackage{setspace}

\usepackage{lipsum} % just for this example

\makeatletter
\def\env@matrix{\hskip -\arraycolsep
  \let\@ifnextchar\new@ifnextchar
  \linespread{1}\selectfont
  \renewcommand{\arraystretch}{1.2}%
  \array{*\c@MaxMatrixCols c}}
\makeatother

\doublespacing

\begin{document}
\lipsum*[2]
\begin{equation}
\mathbf{H} =
 -\bm{\mu} \cdot \mathbf{B} =
 - \gamma B_o \mathbf{S}_z = -\frac{\gamma B_o\hbar}{2}
 \begin{bmatrix} 1&0\\0&-1 \end{bmatrix}.
\end{equation}
\lipsum[3]
\end{document}

Try also without \renewcommand{\arraystretch}{1.2}, that I added in order to space out a bit the rows, which seems better with \doublespacing.

Actually, it's difficult to improve something using \doublespacing, which destroys any attempt at good typography.

enter image description here


In what does this differ from Mico's and Herbert's methods?

Mico's workaround works only within equation. Herbert's instead applies single spacing to all display environments, so also to align, for instance, reducing the line spacing between aligned equations. This might be desirable or not, it depends on you.


Note that {\bf H} should not be used, preferring \mathbf{H}. Also, you'll have noticed that {\bf \mu} doesn't embolden the mu; use \bm{\mu} and load the bm package as in my code.

5

You could use the etoolbox package and use its \AtBeginEnvironment command to reset spacing to \singlespacing at the start of an equation environment.

enter image description here

\documentclass{article}
\usepackage{amsmath}
\usepackage{setspace} % per the OP's information provided in a comment
\doublespacing
\usepackage{etoolbox}
\AtBeginEnvironment{equation}{\singlespacing}
\begin{document}
\begin{equation}
\mathbf{H} = -\boldsymbol{\mu} \cdot \mathbf{B} = - \gamma B_o \mathbf{S}_z = -\frac{\gamma B_o\hbar}{2} 
\begin{bmatrix} 1&0\\0&-1 \end{bmatrix}.
\end{equation}
\end{document}

Remark: This method is quite simple if only the equation environment has to be fixed; it becomes tedious quickly if lots of different display-math environments occur in your document.

0

Well I thought there would be a simple (inelegant) answer and there is! Simply switch to singlespaceing and add some \vspace to make everything hunkydory!

Text here. . .Magnetic resonance imaging blah blah Hamiltonian. . .

\vspace{-0.5cm}
\singlespacing
\begin{equation}
{\bf H} = -{\bf \mu} \cdot {\bf B} = - \gamma B_o {\bf S}_z = -\frac{\gamma B_o\hbar}{2} 
\begin{bmatrix} 1&0\\0&-1 \end{bmatrix}.
\vspace{0.5cm}
\end{equation}
\doublespacing 

Thanks egreg for your comments! Note: egreg warns that this may cause the equation to move to the top of the next page, which is a big no no. Thus, this quick fix may not be the solution for everyone.

Fixed!

3
  • 1
    You probably are leaving a blank line before the equation, which is wrong.
    – egreg
    Oct 10, 2013 at 14:08
  • 3
    Leaving a blank line before an equation means that the equation can end up at the top of the next page, which is a typographic sin worse than leaving a widow line.
    – egreg
    Oct 10, 2013 at 14:39
  • 2
    @egreg and Shinobii: it would be good to clean up and to remove the comments after the issue in the comments is solved. If there's a texnical value in the comments, it could be moved into the answer.
    – Stefan Kottwitz
    Oct 10, 2013 at 15:51

This site is temporarily in read-only mode and not accepting new answers.

Not the answer you're looking for? Browse other questions tagged .