考虑以下 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}
为什么会是这个样子?我希望第一行的单元格具有相同的宽度!
最佳答案
简单,没问题:
\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}|}}
然后我在下面添加了一些其他编辑,以调整对齐方式并在表格边缘添加垂直线(将您的代码与我的代码相对照不会花费您太多时间)。
输出:
今天我将详细阐述一些内容,以统一居中对齐方式并保持列的固定宽度。同时欢迎评论!
关于LaTeX 表格多列产生不均匀的单元宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56413423/