You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LaTeX表格问题:如何让hline从第二列开始且对齐无错位

解决LaTeX表格仅从第二列开始绘制横线的问题

方案1:使用原生\cline命令(推荐,无对齐问题)

直接用\cline{m-n}替代\hline,该命令可指定横线从第m列延伸至第n列,完全满足需求且无需嵌套表格,自然避免对齐错位。

代码示例:

\documentclass[12pt]{standalone}
\begin{document}
\begin{tabular}{l|ccccc||c|}
    \cline{2-7}
    $t_6$   &   0   &   0   &   0   &   -1  &   0   &   0
    \\
    \cline{2-7}
    $t_5$   &   0   &   0   &   0   &   0   &   -1  &   0
    \\
    \cline{2-7}
    $t_4$   &   0   &   0   &   0   &   0   &   0   &   0
    \\
    \cline{2-7}
    $t_3$   &   0   &   0   &   0   &   0   &   1   &   0
    \\
    \cline{2-7}
    $t_2$   &   0   &   0   &   0   &   1   &   0   &   0
    \\
    \cline{2-7}
    $t_1$   &   0   &   0   &   1   &   0   &   0   &   0
    \\
    \cline{2-7}
    $t_0$   &   0   &   1   &   0   &   0   &   0   &   0
    \\
    \cline{2-7}
\end{tabular}
\end{document}

方案2:修复嵌套tabular的对齐问题

若坚持使用嵌套表格,错位原因是内层表格与外层单元格基线对齐不一致,可通过以下调整修复:

  • 外层表格列格式改为{l @{} c @{}},用@{}消除列间默认间距
  • 内层tabular添加[t]参数,强制与外层单元格顶部对齐

代码示例:

\documentclass[12pt]{standalone}
\begin{document}
\begin{tabular}{l @{} c @{}}
    $t_6$   &
    \begin{tabular}[t]{|ccccc||c|}
    \hline
    0   &   0   &   0   &   -1  &   0   &   0
    \\
    \hline
    \end{tabular}
    \\
    $t_5$   &
    \begin{tabular}[t]{|ccccc||c|}
    \hline
    0   &   0   &   0   &   0   &   -1  &   0
    \\
    \hline
    \end{tabular}
    \\
    $t_4$   &
    \begin{tabular}[t]{|ccccc||c|}
    \hline
    0   &   0   &   0   &   0   &   0   &   0
    \\
    \hline
    \end{tabular}
    \\
    $t_3$   &
    \begin{tabular}[t]{|ccccc||c|}
    \hline
    0   &   0   &   0   &   0   &   1   &   0
    \\
    \hline
    \end{tabular}
    \\
    $t_2$   &
    \begin{tabular}[t]{|ccccc||c|}
    \hline
    0   &   0   &   0   &   1   &   0   &   0
    \\
    \hline
    \end{tabular}
    \\
    $t_1$   &
    \begin{tabular}[t]{|ccccc||c|}
    \hline
    0   &   0   &   1   &   0   &   0   &   0
    \\
    \hline
    \end{tabular}
    \\
    $t_0$   &
    \begin{tabular}[t]{|ccccc||c|}
    \hline
    0   &   1   &   0   &   0   &   0   &   0
    \\
    \hline
    \end{tabular}
\end{tabular}
\end{document}

总结

方案1是最简洁的原生解决方案,无需额外调整即可实现需求;方案2适合必须使用嵌套表格的场景,通过简单参数调整解决对齐问题。两者均无需加载额外宏包。

内容的提问来源于stack exchange,提问作者Pehnny

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 19:39:53