表格内表的外观问题

表格内表的外观问题

我想知道我在格式化表格时哪里做错了。我想在另一个表格的每个单元格中都放一个表格,每个表格都应该用文本作为下标。如果您想回答这些问题,请将以下代码复制到您的 LaTeX 编辑器中。

我有一张外面的桌子 := OT 和三张里面的桌子 := IT。

你看,我有一个。如果我尝试在 OT 结尾之前\toprule输入,文档将不再编译(尝试在代码中取消注释它)。如果我在 IT 之前或之后的 OT 单元格内输入一个单词,并用或分隔该单词,我会遇到严重的表格外观问题,我无法理解(尝试取消注释文档中的所有“单词”)。\bottomrule\\word \\\\ word

您能否尝试这两点并告诉我我的格式错误在哪里?

\documentclass{article}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{colortbl}
\begin{document}
\pagenumbering{gobble}
\centering
\renewcommand{\tabcolsep}{0.4cm}
\renewcommand{\arraystretch}{2}
\begin{tabular}{c|c|c}
\toprule %\\ word
        \begin{tabular}{|c|c|c|} 
        \cline{1-3} f&f&f\\ \cline{1-3} t&t&t\\ \cline{1-3} \cellcolor[gray]{0}t&t&t \\ \cline{1-3}
        \end{tabular}  
& %\\ word
        \begin{tabular}{|c|c|c|} 
        \cline{1-3} t&t&t\\ \cline{1-3} \cellcolor[gray]{0}t&t&t\\ \cline{1-3} t&t&t \\ \cline{1-3}
        \end{tabular}  
& %\\ word
        \begin{tabular}{|c|c|c|} 
        \cline{1-3} t&t&t\\ \cline{1-3} \cellcolor[gray]{0}t&t&t\\ \cline{1-3}t &t&t \\ \cline{1-3}
        \end{tabular}  
%\bottomrule
\end{tabular} \\
\end{document}

decription

谢谢你!

答案1

(在原帖作者提供了关于他/她的格式需求的更多关键信息后,我对这个答案进行了重大重写。)

以下可能就是您要找的内容。我对您的代码所做的一些更改包括:(a) 将“内部”tabular环境包裹在subtable环境中;(b) 使用指令排版标题;(c) 内部环境\toprule \bottomrule \hline \cline{1-3}`\caption*之间没有竖线。tabular; (d) make sure the lines drawn byandare no wider than the material they encase; (e) use a lighter coloring for the cells; and (f) userather than

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs,array,ragged2e,subcaption}
\captionsetup[subtable]{justification=Centering} % or: ...=RaggedRight
\usepackage[table]{xcolor}
\newlength\mylength % define length variable
\begin{document}

\pagenumbering{gobble}
\begin{table}
\centering
\renewcommand{\tabcolsep}{0.4cm}
\renewcommand{\arraystretch}{2}
% Calculate overall width of the 3x3 subtables
\settowidth\mylength{\begin{tabular}{|c|c|c|}t&t&t\end{tabular}}

\begin{tabular}{@{}ccc@{}} % outer tabular
\toprule 
\begin{subtable}[t]{\mylength}
        \begin{tabular}{|c|c|c|} % first inner tabular
        \hline f&f&f\\ 
        \hline t&t&t\\ 
        \hline \cellcolor[gray]{0.75}t&t&t \\ 
        \hline 
        \end{tabular}
        \caption*{first table, with a two-line caption}
\end{subtable}        
& 
\begin{subtable}[t]{\mylength}
        \begin{tabular}{|c|c|c|} % second inner tabular
        \hline t&t&t\\ 
        \hline \cellcolor[gray]{0.75}t&t&t\\ 
        \hline t&t&t \\ 
        \hline
        \end{tabular}
        \caption*{second table, with an even longer caption}
\end{subtable}
& 
\begin{subtable}[t]{\mylength}
        \begin{tabular}{|c|c|c|} % third inner tabular
        \hline t&t&t\\ 
        \hline \cellcolor[gray]{0.75}t&t&t\\ 
        \hline t&t&t \\ 
        \hline
        \end{tabular}
        \caption*{third table, with a tremendously long, fancy, and elaborate caption}
\end{subtable} \\ % <--- the "\\" directive is important
\bottomrule
\end{tabular}
\end{table}
\end{document}

答案2

如果我理解得没错的话,这里有两种方法可以实现你想要的效果。我colortblxcolor选项table(加载 colortbl,并添加一些用于着色表格的命令)替换了加载。

\documentclass{article}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage[table]{xcolor}

\begin{document}

\pagenumbering{gobble}
\centering
\renewcommand{\tabcolsep}{0.4cm}
\renewcommand{\arraystretch}{2}
\begin{tabular}{c|c|c}
\toprule
\addlinespace[2ex]
        \begin{tabular}{|c|c|c|}
         \hline f&f&f\\ \hline t&t&t\\  \hline \cellcolor[gray]{0}t&t&t \\ \hline
        \end{tabular}
 & \begin{tabular}{|c|c|c|}
        \hline t&t&t\\ \hline \cellcolor[gray]{0}t&t&t\\ \hline  t&t&t \\ \hline%
    \end{tabular}
&
        \begin{tabular}{|c|c|c|}
        \hline  t&t&t\\ \hline  \cellcolor[gray]{0}t&t&t\\ \hline  t &t&t \\ \hline
        \end{tabular} \\ %
        word & word & word \\
        \bottomrule
\end{tabular} \\
\vspace{1cm}
\begin{tabular}{c|c|c}
\toprule
\addlinespace[2ex]
        \begin{tabular}{|c|c|c|}
        \hline  f&f&f\\ \hline  t&t&t\\ \hline  \cellcolor[gray]{0}t&t&t \\ \hline
        \multicolumn{3}{c}{word}
        \end{tabular}
 & \begin{tabular}{|c|c|c|}
        \hline  t&t&t\\ \hline  \cellcolor[gray]{0}t&t&t\\ \hline  t&t&t \\ \hline
        \multicolumn{3}{c}{word}
        \end{tabular}
&
        \begin{tabular}{|c|c|c|}
        \hline  t&t&t\\ \hline  \cellcolor[gray]{0}t&t&t\\ \hline t &t&t \\ \hline
        \multicolumn{3}{c}{word}
        \end{tabular} \\
        \bottomrule
\end{tabular}

\end{document} 

enter image description here

相关内容