我有如下的一份代码:
\documentclass[fontset=fandol]{ctexart}
\usepackage{geometry}
\usepackage{tabularray}
\usepackage{amsmath,amsfonts}
\begin{document}
\begin{tblr}{
colspec={*{3}{X[c,m]}},
row{1} = {font=\bfseries},
hlines,vlines,
cell{even}{1} = {r=2}{m},
% cell{2-Z}{2-3} = {mode=math},
}
条件 & 方程 & 说明 \\
圆心在原点 & $x^2+y^2=r^2$ & $a=b=0$ \\
& $x^2+y^2+F=0$ & $D=E=0$ \\
圆过原点 & $(x-a)^2+(y-b)^2=a^2+b^2$ & $a^2+b^2=r^2$ \\
& $x^2+y^2+Dx+Ey=0$ & $F=0$ \\
圆心在$x$轴上 & $(x-a)^2+y^2=r^2$ & $b=0$ \\
& $x^2+y^2+Dx+F=0$ & $E=0$ \\
圆心在$y$轴上 & $x^2+(y-b)^2=r^2$ & $a=0$ \\
& $x^2+y^2+Ey+F=0$ & $D=0$ \\
圆与$x$轴相切 & $(x-a)^2+(y-b)^2=b^2$ & $|b|=r$ \\
& {$x^2+y^2+Dx+Ey+F=0$\\$(E\neq 0,D^2-4F=0)$} & $E\neq 0,D^2-4F=0$ \\
圆与$y$轴相切 & $(x-a)^2+(y-b)^2=a^2$ & $|a|=r$ \\
& {$x^2+y^2+Dx+Ey+F=0$\\$(D\neq 0,E^2-4F=0)$} & $D\neq 0,E^2-4F=0$ \\
圆心在$x$轴上且圆过原点 & $(x-a)^2+y^2=a^2$ & $|a|=r,b=0$ \\
& $x^2+y^2+Dx=0$ & $E=F=0,D\neq 0$ \\
圆心在$y$轴上且圆过原点 & $x^2+(y-b)^2=b^2$ & $a=0,|b|=r$ \\
& $x^2+y^2+Ey=0$ & $D=F=0,E\neq 0$ \\
圆与$x,y$轴都相切 & {$(x-a)^2+(y-b)^2=a^2$\\$(|a|=|b|\neq 0)$} & $|a|=|b|=r$ \\
& {$x^2+y^2+Dx+Ey+F=0$\\$(|D|=|E|\neq 0)$} & $D^2=E^2=4F$ \\
\end{tblr}
\end{document}
看上去还行,但我想利用好mode=math
,这样可以批量设置cell{2-Z}{2-3}
的模式,进而少写好多个$
.但是当行内内容需要换行的时候,似乎并不可行。请看下面简化的例子:
\documentclass[fontset=fandol]{ctexart}
\usepackage{geometry}
\usepackage{tabularray}
\usepackage{amsmath,amsfonts}
\begin{document}
\begin{tblr}{
colspec={*{3}{X[c,m]}},
row{1} = {font=\bfseries},
hlines,vlines,
cell{even}{1} = {r=2}{m},
cell{2-Z}{2-3} = {mode=math},
}
条件 & 方程 & 说明 \\
圆心在原点 & x^2+y^2=r^2 & a=b=0 \\
& x^2+y^2+F=0 & D=E=0 \\
圆过原点 & (x-a)^2+(y-b)^2=a^2+b^2 & a^2+b^2=r^2 \\
& x^2+y^2+Dx+Ey=0 & F=0 \\
\end{tblr}
\end{document}
\documentclass[fontset=fandol]{ctexart}
\usepackage{geometry}
\usepackage{tabularray}
\usepackage{amsmath,amsfonts}
\begin{document}
\begin{tblr}{
colspec={*{3}{X[c,m]}},
row{1} = {font=\bfseries},
hlines,vlines,
cell{even}{1} = {r=2}{m},
cell{2-Z}{2-3} = {mode=math},
}
条件 & 方程 & 说明 \\
圆心在原点 & x^2+y^2=r^2 & a=b=0 \\
& x^2+y^2+F=0 & D=E=0 \\
圆过原点 & (x-a)^2+(y-b)^2=a^2+b^2 & a^2+b^2=r^2 \\
& x^2+y^2+Dx+Ey=0 & F=0 \\
圆心在x轴上 & (x-a)^2+y^2=r^2 & b=0 \\
& x^2+y^2+Dx+F=0 & E=0 \\
圆与x,y轴都相切 & {$(x-a)^2+(y-b)^2=a^2$\\$(|a|=|b|\neq 0)$} & |a|=|b|=r \\
& {x^2+y^2+Dx+Ey+F=0\\(|D|=|E|\neq 0)} & D^2=E^2=4F \\
\end{tblr}
\end{document}
其中最后两行当需要在「cell中换行时」
{$(x-a)^2+(y-b)^2=a^2$\\$(|a|=|b|\neq 0)$}
以及
{x^2+y^2+Dx+Ey+F=0\\(|D|=|E|\neq 0)}
都会引发
Missing $ inserted.
<inserted text>
或者
There's no line here to end.
现在从tabularray
用户友好的角度考虑,当用户想要极致利用好mode=math
的功能,同时又遇到这样「需要在行内换行的」排版需求时,是否有优雅的workaround?
inline math
换行的话,可以用 \allowbreak
替换 \\
试试。
\begin{tblr}{
colspec={*{3}{X[c,m]}},
row{1} = {font=\bfseries},
hlines,vlines,
cell{even}{1} = {r=2}{m},
cell{2-Z}{2-3} = {mode=math},
}
条件 & 方程 & 说明 \\
圆心在原点 & x^2+y^2=r^2 & a=b=0 \\
& x^2+y^2+F=0 & D=E=0 \\
圆过原点 & (x-a)^2+(y-b)^2=a^2+b^2 & a^2+b^2=r^2 \\
& x^2+y^2+Dx+Ey=0 & F=0 \\
圆心在x轴上 & (x-a)^2+y^2=r^2 & b=0 \\
& x^2+y^2+Dx+F=0 & E=0 \\
圆与x,y轴都相切 & (x-a)^2+(y-b)^2=a^2 \allowbreak (|a|=|b|\neq 0) & |a|=|b|=r \\
& {x^2+y^2+Dx+Ey+F=0\allowbreak(|D|=|E|\neq 0)} & D^2=E^2=4F \\
\end{tblr}
nice! 感谢!