4

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\\
\endhead
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: 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
4

enter image description here

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\\
\endhead
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[0]\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}
| improve this answer | |
  • +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
  • 1
    @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
2

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[2]{\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\\
\endhead
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}

enter image description here

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\\
\endhead
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\\
\endhead
F & farad & 1 F of capacitance produces a potential difference of 1 V when it has been
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]
\end{longtable}
\end{document}

enter image description here

| improve this answer | |
  • Thanks for the comment! But I'd rather not have to tell LaTeX where to break the lines like that (I could see where the code sample I provided in the original question was misleading in that respect--I initially broke the lines there in order to improve readability, but edited it just now to more closely reflect my intent). I'm still open to suggestions on how to get the formatting of your second example without having to specify where the line breaks go. – Erin Kiley Mar 24 '15 at 18:32
  • @ErinKiley It ain't pretty, but please see my revision. – Steven B. Segletes Mar 24 '15 at 19:08
  • What a cool solution! Thanks for that, Steven! :) – Paulo Cereda Apr 22 '15 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.