因此,我得到了以下代码:
\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}
并生成下表:
我关心的是右列。我希望看到的是内联数学打破前等号,且后续行上的等号都与“F”后的第一个等号对齐。
我知道可以手动换行并添加缩进,但我有许多类似的行,并且想要一种简单易用的方法让 LaTeX 帮我完成这些操作。有方法吗?
答案1
通常,您会在内联数学中的运算符之后(以显示表达式的延续)和对齐显示的运算符之前进行换行,此时本质上是第一个对齐的新表达式。这里使用内联数学是为了方便自动换行,但可以说它应该像显示一样对齐,因此将其变成=
一个活动字符,该字符排版一个正常的=
( {\string=}
),周围是空格和惩罚以允许换行,负空格确保如果没有发生换行,则空间与正常 = 周围的空间相同,但如果确实发生了换行,则新行以足够的空间开始以对齐初始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}
答案2
修订解决方案(自动换行)
这个修改并不漂亮,但是回应了 OP 对我的原始解决方案的评论,她希望自动换行发生。
此修订通过使 处于=
活动状态并重新定义\frac
(两者均为临时)起作用,如宏 中所体现的那样\crazEQ{width}{content}
。content
实际上是在文本模式下处理的,我策略性地使用了 和\unskip
,\ignorespaces
以避免引入杂散空格,否则可能会导致意外的行断点。 因此,您将看到我的content
论点不需要分隔%
。
因为这个解决方案专门针对 OP 的问题和后续评论,所以它旨在让参数仅由和宏\crazEQ
组成。=
\frac{}{}
\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}
原始解决方案(需要手动换行)
这里有两种使用堆栈的替代方法...一种遵循egreg的建议,一种不遵循。
\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}