答案1
{NiceTabular}
这是使用 的自动解决方案nicematrix
。
\documentclass[a4paper]{article}
\usepackage{nicematrix}
\ExplSyntaxOn
\NewDocumentCommand \CenterColumn { m }
{
\cs_if_exist:cT { NiceMatrixSpace _ \NiceMatrixLastEnv }
{ \skip_horizontal:n { \use:c { NiceMatrixSpace _ \NiceMatrixLastEnv } } }
\pgfpicture
\pgfrememberpicturepositiononpagetrue
\pgfextractx \l_tmpa_dim
{
\pgfpointdiff
{
\pgfpointadd
{ \pgfpointanchor { nm - \NiceMatrixLastEnv - 1 } { center } }
{ \pgfpointanchor { nm - \NiceMatrixLastEnv - last } { center } }
}
{
\pgfpointadd
{ \pgfpointanchor { nm - \NiceMatrixLastEnv - #1 } { center } }
{ \pgfpointanchor { nm - \NiceMatrixLastEnv - \int_eval:n { #1 + 1 } } { center } }
}
}
\iow_now:cx { @mainaux }
{
\exp_not:N \expandafter
\gdef
\exp_not:N \csname NiceMatrixSpace _ \NiceMatrixLastEnv \exp_not:N \endcsname
{ \dim_use:N \l_tmpa_dim }
}
\endpgfpicture
}
\ExplSyntaxOff
\begin{document}
\begin{table}[t]
\centering
\begin{NiceTabular}{cccc}
Abc & ~~ & Abc & Abc \\
efg & ~~ & efg & efg \\
\end{NiceTabular}
\CenterColumn{2}
\caption{Caption}
\end{table}
\begin{table}[t]
\centering
\begin{NiceTabular}{ccccc}
Abc & ~~ & Abc & Abc & extra \\
efg & ~~ & efg & efg & something \\
\end{NiceTabular}
\CenterColumn{2}
\caption{Caption}
\label{tab:my_label}
\end{table}
\begin{table}[t]
\centering
\begin{NiceTabular}{ccccc}
extra & Abc & ~~ & Abc & Abc \\
something & efg & ~~ & efg & efg \\
\end{NiceTabular}
\CenterColumn{3}
\caption{Caption}
\label{tab:my_label}
\end{table}
\end{document}
您需要多次编译(因为信息写在aux
文件中)。