![包含多列行的表格](https://linux22.com/image/469348/%E5%8C%85%E5%90%AB%E5%A4%9A%E5%88%97%E8%A1%8C%E7%9A%84%E8%A1%A8%E6%A0%BC.png)
我正在尝试格式化一个包含多列的表格,以便每行的空单元格都有一条连续的彩色线条穿过它们。我尝试过调整一个multicolumn
包含命令的命令,但它并不总是能得到我想要的结果。尽管在环境中rule
指定了,但我的表格也超出了边距。\textwidth
tabular*
我不完全理解多列和的语法,tabular
因此extracolsep
任何见解都会受到赞赏。
请参阅下面的代码。前两个表格是试运行的。第二个表格没有按预期工作,因为第 1 行和第 2 行中的线条应该显示出来。第三个表格超出了边距,并且没有使用multicolumn
。第四个表格使用了multicolumn
,但rule
线条格式很差。
我是否缺少任何相关的包?
感谢您的帮助!
\documentclass[12pt]{article}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[latin1]{inputenc}
\usepackage{array}
\usepackage{multirow}
\usepackage{tikz}
\begin{document}
\begin{table}[ht]
\caption{Working (though some parameters are unclear to me)}
\begin{tabular}{ p{3cm} p{3cm} p{3cm} }
\multicolumn{2}{@{\extracolsep{\fill}}c@{\hskip 1cm}}{\leaders\hbox{\rule[0.2em]{.1pt}{0.4pt}}\hfill\mbox{}} & 3 \\
4 & \multicolumn{2}{@{\extracolsep{\fill}}c@{\hskip 1cm}}{\leaders\hbox{\rule[0.2em]{.1pt}{0.4pt}}\hfill\mbox{}} \\
7 & 8 & 9 \\
\end{tabular}
\end{table}
\begin{table}[ht]
\caption{Not working (lines in rows 1 and 2 not showing; very small)}
\begin{tabular}{ p{3cm} p{3cm} p{3cm} }
\multicolumn{2}{@{\extracolsep{\fill}}c@{\hskip 1cm}}{\leaders\hbox{\rule[0.2em]{.1pt}{0.4pt}}\hfill\mbox{}} & 3 \\
4 & \multicolumn{2}{@{\extracolsep{\fill}}c@{\hskip 1cm}}{\leaders\hbox{\rule[0.2em]{.1pt}{0.4pt}}\hfill\mbox{}} \\
\multicolumn{2}{@{\extracolsep{\fill}}c@{\hskip 0cm}}{\leaders\hbox{\rule[0.2em]{.1pt}{0.4pt}}\hfill\mbox{}} & 9 \\
\end{tabular}
\end{table}
\begin{table}[ht]
\caption{Extending past margin (original code to be adpated using multicolumn)}
\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}}>{\centering}p{1.5mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{3mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{2mm}>{\raggedright}p{1.5mm}>{\raggedright}p{4mm}>{\raggedright}p{4mm}>{\centering}p{2mm}}
\hline
\noalign{\vskip2mm}
\multirow{1}{1.5mm}{{\footnotesize{}$m$}} & \multicolumn{15}{l}{{\footnotesize{}text}} & \tabularnewline[2mm]
\hline
\noalign{\vskip2mm}
{\footnotesize{}1} & \textcolor{blue}{\rule[0.5ex]{166mm}{2pt}} & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & {\footnotesize{}text1 }\tabularnewline
{\footnotesize{}2} & \textcolor{blue}{\rule[0.5ex]{153mm}{2pt}} & & & & & & & & & & & & & & & & & & & & & & & & & & & & {\footnotesize{}text2} & {\footnotesize{}text3} & \textcolor{blue}{\rule[0.5ex]{3mm}{2pt}}\tabularnewline
\end{tabular*}
\end{table}
\begin{table}[ht]
\caption{Lines of wrong length; poor formatting; extends past margin if adding more text}
\begin{tabular*}{1\textwidth}{@{\extracolsep{\fill}}>{\centering}p{1.5mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{3mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{2mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{3mm}>{\raggedright}p{2mm}>{\raggedright}p{1.5mm}>{\raggedright}p{4mm}>{\raggedright}p{4mm}>{\centering}p{2mm}}
\hline
\noalign{\vskip2mm}
\multirow{1}{1.5mm}{{\footnotesize{}$m$}} & \multicolumn{15}{l}{{\footnotesize{}text}} & \tabularnewline[2mm]
\hline
\noalign{\vskip2mm}
{\footnotesize{}1} & \multicolumn{30}{@{\extracolsep{\fill}}c@{\hskip 1cm}}{\leaders\hbox{\textcolor{blue}{\rule[0.2em]{0.1pt}{0.4pt}}}\hfill\mbox{}} & {\footnotesize{}text1 }\tabularnewline
{\footnotesize{}2} & \multicolumn{28}{@{\extracolsep{\fill}}c@{\hskip 1cm}}{\leaders\hbox{\textcolor{blue}{\rule[0.2em]{0.1pt}{0.4pt}}}\hfill\mbox{}} & {\footnotesize{}text2} & {\footnotesize{}text3} & \multicolumn{1}{@{\extracolsep{\fill}}c@{\hskip 1cm}}{\leaders\hbox{\textcolor{blue}{\rule[0.2em]{0.1pt}{0.4pt}}}\hfill\mbox{}}\tabularnewline
\end{tabular*}
\end{table}
\end{document}