30 对于tabularray宏包,对于需要在行内手动换行的单元格,是否有办法批量设置「mode=math」?

发布于 2025-09-06 13:13:25

我有如下的一份代码:

\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}

image.png

看上去还行,但我想利用好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}

当我新增一行需要在cell内部换行的内容:

\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?

查看更多

关注者
0
被浏览
71
M
M 2小时前
这家伙很懒,什么也没写!

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}

局部截取_20250906_174746.png

2 个回答
Sagittarius Rover
Sagittarius Rover 6小时前
这家伙很懒,什么也没写!

直观上一种可行的办法也许是把多余的行一分为二...

image.png

但这样的坏处也是显然的:

  • 无法吃到cell{even}{1} = {r=2}{m}这样的糖的福利
  • 其他位置要多写好几个cell合并...

为了吃上mode=math的红利,而放弃了其他代码的简洁性,这也是我不太能接受的...

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览