01/08/2013

LaTeX equations split over two columns

Drafting a paper I've just got stuck trying to fit some lengthy equations into a two column document. For some I've gotten away with splitting lines using \begin{split} or \begin{align} environments, but for some it starts to look ridiculous. I also started to run into issues where my \left( and \right) bracket commands didn't like to be split over lines. So I decided that there was no option except spreading the equation over the full page width.

This is actually not particularly straightforward in LaTeX. A reasonable forum discussion on options gives a few suggestions. It seems that it needs to be floated within a figure environment. This is also suggested in a very comprehensive document (p35) on typesetting equations. Unfortunately both of these require manual fiddling with equation numbers and quite a lot of extra code in the document. I've therefore modified their code to define my own environment for a floated equation and used counters to automate the equation numbering.

Preamble:
% for floated 2 column equations
\newcounter{tempEquationCounter}
\newcounter{thisEquationNumber}
\newenvironment{floatEq}
{\setcounter{thisEquationNumber}{\value{equation}}\addtocounter{equation}{1}% record equation as happened and remember number
\begin{figure*}[!t]% float following equation across columns
\normalsize\setcounter{tempEquationCounter}{\value{equation}}% record current equation number in floated location
\setcounter{equation}{\value{thisEquationNumber}}% use previous equation number
}
{\setcounter{equation}{\value{tempEquationCounter}}% set back to equation number in floated location
\hrulefill\vspace*{4pt}% add a horizontal rule separator
\end{figure*}% end float environment

}

In the text simply wrap the standard equation environment in the new environment:
\begin{floatEq}
\begin{equation}
a = b + c
\label{equ:floatedEquation}
\end{equation}
\end{floatEq}

This should float the equation across the whole page and allow LaTeX to fit it in the right place whilst still numbering it as if it appeared where it is defined in the text. Or at least that's what it's achieving for me at the moment!

5 comments:

  1. It was very helpful. Thanks!

    ReplyDelete
  2. Thanks. It was really helpful.

    ReplyDelete
  3. Thank you..very useful...I updated it more to have option of bottom or bottom of page placement

    \newcounter{tempEquationCounter}
    \newcounter{thisEquationNumber}

    %% Floats At Top of the page
    %---------------------------
    \newenvironment{floatEqTop}
    {\setcounter{thisEquationNumber}{\value{equation}}\addtocounter{equation}{1}% record equation as happened and remember number
    \begin{figure*}[!t]% float following equation across columns
    \normalsize\setcounter{tempEquationCounter}{\value{equation}}% record current equation number in floated location
    \setcounter{equation}{\value{thisEquationNumber}}% use previous equation number
    }
    {\setcounter{equation}{\value{tempEquationCounter}}% set back to equation number in floated location
    \hrulefill\vspace*{4pt}% add a horizontal rule separator
    \end{figure*}% end float environment
    }

    %% Floats At Bottom of the page
    %------------------------------
    \newenvironment{floatEqBtm}
    {\setcounter{thisEquationNumber}{\value{equation}}\addtocounter{equation}{1}% record equation as happened and remember number
    \begin{figure*}[!b]% float following equation across columns
    \vspace*{4pt}\hrulefill% add a horizontal rule separator
    \normalsize\setcounter{tempEquationCounter}{\value{equation}}% record current equation number in floated location
    \setcounter{equation}{\value{thisEquationNumber}}% use previous equation number
    }
    {\setcounter{equation}{\value{tempEquationCounter}}% set back to equation number in floated location
    \end{figure*}% end float environment
    }

    ReplyDelete