【问题标题】:LaTeX tabular multicolumn produces uneven cell widthsLaTeX表格多列产生不均匀的单元格宽度
【发布时间】:2019-06-02 08:29:50
【问题描述】:

考虑使用 LaTeX 代码:

\begin{tabular}{c|c|c|c|c|c|c|c|c}
    \hline
    \textbf{Bit $\rightarrow$} & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\\
    \hline
    Byte 1 & \multicolumn{4}{c|}{MQTT Control Packet type} & \multicolumn{4}{c}{Flags specific to each MQTT Control Packet type}\\
    \hline
    Byte 2 & \multicolumn{8}{c}{Remaining Length}\\
    \hline
\end{tabular}

为什么会这样?我希望第一行的单元格具有相同的宽度!

【问题讨论】:

    标签: latex tabular


    【解决方案1】:

    简单,没问题:

    \documentclass{article}
    
    \begin{document}
    
    \begin{tabular}{|*{9}{p{11mm}|}}
        \hline
        \textbf{Bit $\rightarrow$} & 7 & 6 & 5 & 4 & 3 & 2 & 1 & 0\\
        \hline
        Byte 1 & \multicolumn{4}{c|}{MQTT Control Packet type} & \multicolumn{4}{p{50mm}|}{Flags specific to each MQTT Control Packet type}\\
        \hline
        Byte 2 & \multicolumn{8}{c|}{Remaining Length}\\
        \hline
    \end{tabular}
    
    \end{document}
    

    主要是换行:

    \begin{tabular}{c|c|c|c|c|c|c|c|c}
    

    \begin{tabular}{|p{11mm}|p{11mm}|p{11mm}|p{11mm}|p{11mm}|p{11mm}|p{11mm}|p{11mm}|p{11mm}|}
    

    或者,更好的是

    \begin{tabular}{|*{9}{p{11mm}|}}
    

    然后我在下面添加了一些其他编辑以调整对齐方式并在表格边缘添加垂直线(用我的代码面对您的代码不会花费您太多时间)。

    输出:

    到今天为止,我将进一步详细说明,以统一居中对齐以保持列的固定宽度。欢迎随时发表评论!

    【讨论】:

    • 非常感谢!这正是我希望桌子看起来的样子。仍然有点费力,但它有效:)
    • @binaryBigInt 谢谢,很高兴为您提供帮助!但至少看看array 包中的\newcolumntype 命令,以一致地调整所有单元格的对齐方式。示例:tex.stackexchange.com/questions/257128/…
    猜你喜欢
    • 1970-01-01
    • 2011-04-28
    • 1970-01-01
    • 2011-02-20
    • 1970-01-01
    • 1970-01-01
    • 2012-04-04
    • 2012-07-31
    • 2019-11-16
    相关资源
    最近更新 更多