# Breaking inline math within longtable or tabular

So, I've got the following code:

\documentclass{memoir}
\usepackage{longtable}
\begin{document}
\begin{longtable}{p{0.4in}cp{2.75in}p{1.8in}}
Symbol & Unit & Describes & Equivalent Units\\
\hline\\
F & farad & 1 F of capacitance produces a potential difference of 1 V when it has been charged by 1 C & $\textrm{F}=\frac{\textrm{A}\cdot\textrm{s}}{\textrm{V}}=\frac{\textrm{J}}{\textrm{V}^2}=\frac{\textrm{W}\cdot\textrm{s}}{\textrm{V}^2}=\frac{\textrm{C}}{\textrm{V}}=\frac{\textrm{C}^2}{\textrm{J}}=\frac{\textrm{C}^2}{\textrm{N}\cdot\textrm{m}}=\frac{\textrm{s}^2\cdot\textrm{C}^2}{\textrm{m}^2\cdot\textrm{kg}}=\frac{\textrm{s}^4\cdot\textrm{A}^2}{\textrm{m}^2\cdot\textrm{kg}}=\frac{\textrm{s}}{\Omega}$\\[2.5em]
\end{longtable}
\end{document}


And it produces this table: I'm concerned about the rightmost column. What I'd like to see is the inline math breaking just before the equals signs, and with the equals signs on subsequent lines all aligned with the first one after the "F".

I know could manually break the lines and add indentations, but I'll have a number of similar rows and would like a nice/simple way of telling LaTeX to do this for me. Is there one?

• In line math is broken after equals signs and it's the correct way. – egreg Mar 24 '15 at 17:40
• inline math always (and only) breaks after relations and infix binary operators, unless you add manual line breaking hints – David Carlisle Mar 24 '15 at 17:41 Normally you break after operators in inline math (to show the expression carries over) and before operators in an aligned display, where it is essentially a new expression aligned on the first. Here inline math is being used as a convenience to get automatic breaking but arguably it should align like a display, so make = into an active character that typesets a normal = ({\string=}) surrounded by spacing and a penalty to allow line break, the negative space ensures that if a linebreak does not happen the space is the same as around a normal = but if a linebreak does happen the new line starts with space sufficient to align on the initial F= .

\documentclass{memoir}
\usepackage{longtable}
\begin{document}
\begin{longtable}{p{0.4in}cp{2.75in}p{1.8in}}
Symbol & Unit & Describes & Equivalent Units\\
\hline\\
F & farad & 1 F of capacitance produces a potential difference of 1 V when it has been charged by 1 C &
\raggedright
\catcode\=\active
\settowidth{\dimen0}{$\mathrm{F}$}%
\def={\hbox{\hskip-\dimen0}\linebreak\hbox{\hskip\dimen0}\>{\string=}\>}%
$\mathrm{F}=\frac{\mathrm{A}\cdot\mathrm{s}}{\mathrm{V}}= \frac{\mathrm{J}}{\mathrm{V}^2}= \frac{\mathrm{W}\cdot\mathrm{s}}{\mathrm{V}^2}= \frac{\mathrm{C}}{\mathrm{V}}= \frac{\mathrm{C}^2}{\mathrm{J}}= \frac{\mathrm{C}^2}{\mathrm{N}\cdot\mathrm{m}}= \frac{\mathrm{s}^2\cdot\mathrm{C}^2}{\mathrm{m}^2\cdot\mathrm{kg}}= \frac{\mathrm{s}^4\cdot\mathrm{A}^2}{\mathrm{m}^2\cdot\mathrm{kg}}= \frac{\mathrm{s}}{\Omega}$\\[2.5em]
\end{longtable}
\end{document}

• +1. You may to add a brief verbal description of what making = active and making it into a macro is doing. – Mico Apr 22 '15 at 11:04
• @Mico, you mean my code isn't wonderfully self documenting and clear?:-) I suppose I could add some words... – David Carlisle Apr 22 '15 at 11:56

REVISED SOLUTION (auto linebreak)

This revision is not pretty, but responds to the OP's comment to my original solution that she would like auto-linebreaks to happen.

This revision works by making = active and redefining \frac, both temporarily, as embodied in the macro \crazEQ{width}{content}. The content is actually processed in text mode, and I use a strategically placed \unskip and \ignorespaces to avoid introducing stray space that would otherwise risk causing an unintended line breakpoint. Thus, you will see my content argument does not need to be % delimited.

Because this solution is specifically geared to the OP's question and follow-up comment, it is intended that arguments to \crazEQ be composed solely of = and \frac{}{} macros.

\documentclass{memoir}
\usepackage{longtable}
\let\svfrac\frac
\catcode=\active%
\newcommand\crazEQ{\mathrel{%
\def\frac##1##2{\unskip~$\svfrac{##1}{##2}$\ \ignorespaces}%
\catcode=\active%
\def={\char61}%
\parbox[t]{#1}{\raggedright#2}%
\catcode=12\let\frac\svfrac%
}}
\catcode=12
\begin{document}
\begin{longtable}{p{0.4in}cp{2.75in}p{1.8in}}
Symbol & Unit & Describes & Equivalent Units\\
\hline\\
F & farad & 1 F of capacitance produces a potential difference of 1 V when it has been
charged by 1 C & $\textrm{F}\crazEQ{1.7in}{ = \frac{\textrm{A}\cdot\textrm{s}}{\textrm{V}} = \frac{\textrm{J}}{\textrm{V}^2} = \frac{\textrm{W}\cdot\textrm{s}}{\textrm{V}^2} = \frac{\textrm{C}}{\textrm{V}} = \frac{\textrm{C}^2}{\textrm{J}}= \frac{\textrm{C}^2}{\textrm{N}\cdot\textrm{m}} =\frac{\textrm{s}^2\cdot\textrm{C}^2}{\textrm{m}^2\cdot\textrm{kg}}= \frac{\textrm{s}^4\cdot\textrm{A}^2}{\textrm{m}^2\cdot\textrm{kg}}= \frac{\textrm{s}}{\Omega} }$\\[2.5em]
\end{longtable}
\end{document} ORIGINAL SOLUTION (requiring manual linebreaks)

Here are two alternatives using stacks... one following egreg's recommendation, and one not.

\documentclass{memoir}
\usepackage{longtable,stackengine}
\stackMath
\begin{document}
\begin{longtable}{p{0.4in}cp{2.75in}p{1.8in}}
Symbol & Unit & Describes & Equivalent Units\\
\hline\\
F & farad & 1 F of capacitance produces a potential difference of 1 V when it has been
charged by 1 C & $\textrm{F}=\Shortunderstack[l]{% \frac{\textrm{A}\cdot\textrm{s}}{\textrm{V}}=% \frac{\textrm{J}}{\textrm{V}^2}=\frac{\textrm{W}\cdot\textrm{s}}{\textrm{V}^2}= \frac{\textrm{C}}{\textrm{V}}=\frac{\textrm{C}^2}{\textrm{J}}=% \frac{\textrm{C}^2}{\textrm{N}\cdot\textrm{m}}= \frac{\textrm{s}^2\cdot\textrm{C}^2}{\textrm{m}^2\cdot\textrm{kg}}=% \frac{\textrm{s}^4\cdot\textrm{A}^2}{\textrm{m}^2\cdot\textrm{kg}}=% \frac{\textrm{s}}{\Omega}% }$\\[2.5em]
\end{longtable}

\begin{longtable}{p{0.4in}cp{2.75in}p{1.8in}}
Symbol & Unit & Describes & Equivalent Units\\
\hline\\
charged by 1 C & $\textrm{F}\mathrel{\Shortunderstack[l]{% =\frac{\textrm{A}\cdot\textrm{s}}{\textrm{V}}=% \frac{\textrm{J}}{\textrm{V}^2}=\frac{\textrm{W}\cdot\textrm{s}}{\textrm{V}^2} =\frac{\textrm{C}}{\textrm{V}}=\frac{\textrm{C}^2}{\textrm{J}}=% \frac{\textrm{C}^2}{\textrm{N}\cdot\textrm{m}} =\frac{\textrm{s}^2\cdot\textrm{C}^2}{\textrm{m}^2\cdot\textrm{kg}}=% \frac{\textrm{s}^4\cdot\textrm{A}^2}{\textrm{m}^2\cdot\textrm{kg}}=% \frac{\textrm{s}}{\Omega}% }}$\\[2.5em] • What a cool solution! Thanks for that, Steven! :)` – Paulo Cereda Apr 22 '15 at 12:27