LaTeX表格中公式标签对齐问题求助
LaTeX表格公式标签对齐解决方案
问题描述
我使用以下LaTeX代码创建表格:
\begin{table}[] \centering \renewcommand{\arraystretch}{1} \caption{Example table.} \label{tab:model-testbed} \renewcommand{\arraystretch}{1.1} \resizebox{\linewidth}{!}{% \begin{tabular}{|c|l|l|} \hline Comment & \multicolumn{1}{c|}{Device1} & \multicolumn{1}{c|}{Device2} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla \\ Sth \end{tabular} & \begin{tabular}[c]{@{}l@{}} \begin{equation} \tag{1}\label{t3:1} \begin{aligned} y(x) = 66.1 + 1.11x - 1.28 \times 10^{-8}x^2 \\ +15.08 \times 10^{-2}x^1 \end{aligned} \end{equation} \end{tabular} & \begin{tabular}[c]{@{}l@{}} \begin{equation} \tag{2}\label{t3:2} \begin{aligned} y(x) =20.33 + 1.24y - 1.74 \times 10^{-1}x^5 \\ + 1.14 \times 10^{-7}y^5 \end{aligned} \end{equation} \end{tabular} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla \\ Sth\end{tabular} & \begin{equation} \tag{3}\label{t3:3} \begin{aligned} w(x) =2.13 + 0.03x \end{aligned} \end{equation} & \begin{equation} \tag{4} \label{t3:4} \begin{aligned} er(x) =4.85 + 33.56y \end{aligned} \end{equation} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla\\ Sth\end{tabular} & \begin{equation} \tag{5}\label{t3:5} \begin{aligned} b(x) =12.2 + 5.20y \end{aligned} \end{equation} & \begin{equation} \tag{6}\label{t3:6} \begin{aligned} a(x) =1.11 + 1.11x - 2.543 \times 10^{-2}x^2 \end{aligned} \end{equation} \hline \end{tabular}} \end{table}
生成的表格中,公式旁的标签(如(1)(3)等)紧邻公式,希望将所有标签对齐,但尝试用\hspace{1cm}调整无效,求解决方法。
解决方案
方法一:用minipage固定宽度+hfill推标签右对齐
放弃单元格内的equation环境,改用minipage限定公式区域宽度,aligned排版公式,\hfill将标签推到区域最右侧,实现同一列标签对齐。
修改后的代码:
\begin{table}[] \centering \renewcommand{\arraystretch}{1} \caption{Example table.} \label{tab:model-testbed} \renewcommand{\arraystretch}{1.1} \resizebox{\linewidth}{!}{% \begin{tabular}{|c|l|l|} \hline Comment & \multicolumn{1}{c|}{Device1} & \multicolumn{1}{c|}{Device2} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla \\ Sth \end{tabular} & \begin{minipage}{0.3\textwidth} \begin{aligned} y(x) = 66.1 + 1.11x - 1.28 \times 10^{-8}x^2 \\ +15.08 \times 10^{-2}x^1 \end{aligned} \hfill \tag{1}\label{t3:1} \end{minipage} & \begin{minipage}{0.3\textwidth} \begin{aligned} y(x) =20.33 + 1.24y - 1.74 \times 10^{-1}x^5 \\ + 1.14 \times 10^{-7}y^5 \end{aligned} \hfill \tag{2}\label{t3:2} \end{minipage} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla \\ Sth\end{tabular} & \begin{minipage}{0.3\textwidth} \begin{aligned} w(x) =2.13 + 0.03x \end{aligned} \hfill \tag{3}\label{t3:3} \end{minipage} & \begin{minipage}{0.3\textwidth} \begin{aligned} er(x) =4.85 + 33.56y \end{aligned} \hfill \tag{4}\label{t3:4} \end{minipage} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla\\ Sth\end{tabular} & \begin{minipage}{0.3\textwidth} \begin{aligned} b(x) =12.2 + 5.20y \end{aligned} \hfill \tag{5}\label{t3:5} \end{minipage} & \begin{minipage}{0.3\textwidth} \begin{aligned} a(x) =1.11 + 1.11x - 2.543 \times 10^{-2}x^2 \end{aligned} \hfill \tag{6}\label{t3:6} \end{minipage} \\ \hline \end{tabular}} \end{table}
方法二:拆分表格列,单独放置标签
调整表格列结构,将Device1和Device2的列拆成「公式左对齐列+标签右对齐列」,利用表格列的对齐特性实现标签统一对齐。
修改后的代码:
\begin{table}[] \centering \renewcommand{\arraystretch}{1} \caption{Example table.} \label{tab:model-testbed} \renewcommand{\arraystretch}{1.1} \resizebox{\linewidth}{!}{% \begin{tabular}{|c|l@{}r|l@{}r|} \hline Comment & \multicolumn{2}{c|}{Device1} & \multicolumn{2}{c|}{Device2} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla \\ Sth \end{tabular} & \begin{aligned} y(x) = 66.1 + 1.11x - 1.28 \times 10^{-8}x^2 \\ +15.08 \times 10^{-2}x^1 \end{aligned} & \tag{1}\label{t3:1} & \begin{aligned} y(x) =20.33 + 1.24y - 1.74 \times 10^{-1}x^5 \\ + 1.14 \times 10^{-7}y^5 \end{aligned} & \tag{2}\label{t3:2} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla \\ Sth\end{tabular} & \begin{aligned} w(x) =2.13 + 0.03x \end{aligned} & \tag{3}\label{t3:3} & \begin{aligned} er(x) =4.85 + 33.56y \end{aligned} & \tag{4}\label{t3:4} \\ \hline \begin{tabular}[c]{@{}c@{}}BlaBla\\ Sth\end{tabular} & \begin{aligned} b(x) =12.2 + 5.20y \end{aligned} & \tag{5}\label{t3:5} & \begin{aligned} a(x) =1.11 + 1.11x - 2.543 \times 10^{-2}x^2 \end{aligned} & \tag{6}\label{t3:6} \\ \hline \end{tabular}} \end{table}
这里l@{}r表示左对齐列和右对齐列之间无间隔,公式放在左列,标签放在右列,同一设备列的所有标签会自动对齐在列的右侧,效果更规整。
内容的提问来源于stack exchange,提问作者Tricker Macedonia
相关产品推荐
相关产品推荐

