我不明白为什么第三列(N)的宽度与其他列不同

我不明白为什么第三列(N)的宽度与其他列不同

在此处输入图片描述 我尝试使用\!\hspace{-1em}

这是一个最小工作示例:

\documentclass[]{article}

\usepackage{multirow}
\usepackage{booktabs}
\usepackage{xcolor,colortbl}
\newcolumntype{?}[1]{!{\vrule width #1}}
%opening
\title{}
\author{}

\begin{document}
%Checkout https://texblog.org/2014/05/19/coloring-multi-row-tables-in-latex/
% and https://www.baeldung.com/cs/latex-tables-vertical-horizontal
\begin{table}[tbp]
    \centering
    \caption[Comparison of all model predictions for of genetic circuit failures, and the most ``robust" circuit choice for each model simulation.]{Comparison of all model predictions for of genetic circuit failures, and the most ``robust" circuit choice for each model simulation. \textbf{D}: default parameter values; \textbf{C}: characterized parameter values; \textbf{O}: original design; \textbf{T}: two-inverter design; \textbf{N}: no-logic-hazard design (or logic-hazard free design).}
    \begin{tabular}{c|c|c|c|c?{2pt}c|c|c?{2pt}c|c|c|}
        \toprule
        \multicolumn{2}{c}{} & \multicolumn{3}{c}{\textbf{Default Model}} & \multicolumn{6}{c}{\textbf{Cello Model}}\\
        \multicolumn{2}{c}{} & \multicolumn{3}{c}{D} & \multicolumn{3}{c}{D} & \multicolumn{3}{c}{C} \\
        \cmidrule(rl){3-5} \cmidrule(rl){6-8} \cmidrule(rl){9-11}
        \multicolumn{2}{c}{\textbf{Circuit Failures}}&   O   &   T   & N &   O   &   T   &   N   &   O   &   T   &   N   \\
        \midrule
        & $(0,1,0) \rightarrow (1,1,1)$ & & \cellcolor{red} & & & \cellcolor{red} & \cellcolor{lime} & & \cellcolor{red} & \\ 
        & $(0,1,0) \rightarrow (1,0,0)$ & & & \cellcolor{lime} & & \cellcolor{red} & \cellcolor{lime} & & & \cellcolor{lime} \\
        & $(1,1,1) \rightarrow (1,0,0)$ & \cellcolor{red} & & \cellcolor{lime} & & & \cellcolor{lime} & & \cellcolor{red} & \\      
        & $(1,1,1) \rightarrow (0,1,0)$ & & \cellcolor{lime} & & & \cellcolor{lime} & \cellcolor{red} & & & \\
        & $(1,0,0) \rightarrow (0,1,0)$ & \cellcolor{red} & \cellcolor{lime} & & & \cellcolor{lime} & \cellcolor{red} & \cellcolor{red} & & \cellcolor{lime}\\
        \multirow{-6}{*}{0-Function Hazards}& $(1,0,0) \rightarrow (1,1,1)$ & & \cellcolor{red} & \cellcolor{lime} & &\cellcolor{red} & & & \cellcolor{red} & \\
        \specialrule{\cmidrulewidth}{3pt}{3pt}
        & $(0,1,1) \rightarrow (1,0,1)$ & & \cellcolor{lime} & & \cellcolor{red} & \cellcolor{lime} & & \cellcolor{red} & & \cellcolor{lime}\\
        & $(0,0,0) \rightarrow (0,1,1)$ & \cellcolor{lime} & \cellcolor{red} & & \cellcolor{lime} & \cellcolor{red} & & \cellcolor{lime} & & \\
        & $(0,0,0) \rightarrow (1,0,1)$ & & \cellcolor{lime} & & & \cellcolor{lime} & & & \cellcolor{lime} & \cellcolor{red}\\
        & $(1,0,1) \rightarrow (0,1,1)$ & & & & & \cellcolor{red}& \cellcolor{lime} & \cellcolor{lime} & \cellcolor{red} &  \\      
        & $(0,1,1) \rightarrow (0,0,0)$ & & \cellcolor{red} & & \cellcolor{lime} & \cellcolor{red}  & & \cellcolor{lime} & & \cellcolor{red}\\
        \multirow{-6}{*}{1-Function Hazards}& $(1,0,1) \rightarrow (0,0,0)$ & & \cellcolor{red} & & & \cellcolor{red}& \cellcolor{lime} & \cellcolor{lime} & \cellcolor{red} & \\
        \specialrule{\cmidrulewidth}{3pt}{3pt}
        & $(0,0,0)$ & \cellcolor{lime} & \cellcolor{red} & & \cellcolor{lime} & \cellcolor{red} & & \cellcolor{lime} & & \cellcolor{red}\\
        & $(0,0,1)$ & & \cellcolor{red} & \cellcolor{lime} & \cellcolor{lime} & & \cellcolor{red} & & \cellcolor{red} & \cellcolor{lime}\\
        & $(0,1,0)$ & & \cellcolor{red} & \cellcolor{lime} & & & \cellcolor{lime} & & \cellcolor{red} &\cellcolor{lime} \\
        & $(0,1,1)$ & \cellcolor{lime} & \cellcolor{red} & & \cellcolor{lime} & \cellcolor{red} & & \cellcolor{lime} & \cellcolor{red} & \\     
        & $(1,0,0)$ & & & \cellcolor{lime} & & & \cellcolor{lime} & \cellcolor{lime} & & \\
        & $(1,0,1)$ & & \cellcolor{red} & & & \cellcolor{red} & & \cellcolor{red} & & \cellcolor{lime}\\
        & $(1,1,0)$ & & \cellcolor{red} & \cellcolor{lime} & \cellcolor{red} & & & & \cellcolor{red} & \\
        \multirow{-8}{*}{Wrong Steady-State}& $(1,1,1)$ & & \cellcolor{red} & \cellcolor{lime} & & \cellcolor{red} & \cellcolor{lime} & \cellcolor{lime} & \cellcolor{red} & \\
        \bottomrule
    \end{tabular}
    \\[1.5pt]
    \centering
    \small This table compares each models' predictions for best and worst performance for each transition. A red color means that the circuit performed worse than the median, and green color means that the circuit performed better than the median, for that input molecule concentration or transition. 
    \label{tab:failuresALL}
\end{table}
\end{document}

答案1

正如@JasperHabicht 在评论中指出的那样,第 5 列宽度过大的原因是第 3 至第 5 列的标题“太宽”,即字符串“Default Model”的宽度远远超过了三个单独列的总自然宽度。标题字符串的超宽必须反映在一个或多个底层列的实际宽度中。您(重新)发现的是,LaTeX 将超宽分配给宽标题下方的列组中的最后一列。

第二个问题是表格整体太宽,无法放入文本块中。在下面的代码中,我对您的代码进行了各种更改,以使表格适合。其中之一是将上述标题从“默认模型”更改为“默认”。我还建议删除所有垂直规则,以使表格看起来更开放。

在此处输入图片描述

\documentclass{article}

\usepackage[table]{xcolor}
\usepackage{array,booktabs}
\newcolumntype{?}[1]{!{\color{white}\vrule width #1}}

\begin{document}
\begin{table}[tbp]
\newcommand\red{\cellcolor{red}} % handy shortcut macros
\newcommand\lime{\cellcolor{lime}}

\caption[Comparison of all model predictions of genetic circuit failures, and the most ``robust'' circuit choice for each model simulation.]{Comparison of all model predictions of genetic circuit failures, and the most ``robust'' circuit choice for each model simulation. }
\label{tab:failuresALL}

\medskip
\textbf{D}: default parameter values; \textbf{C}: characterized parameter values; \textbf{O}: original design; \textbf{T}: two-inverter design; \textbf{N}: no-logic-hazard design (or logic-hazard free design).
    
\smallskip
\setlength\tabcolsep{4.5pt} % default: 6pt
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} cc ccc ?{3pt} ccc ?{3pt} ccc }
\toprule
\multicolumn{2}{@{}l}{Circuit Failures} & 
\multicolumn{9}{c@{}}{Models} \\
\cmidrule(r){1-2} \cmidrule(l){3-11}
& & \multicolumn{3}{c}{Default} & \multicolumn{6}{c@{}}{Cello}\\
\cmidrule(lr){3-5} \cmidrule{6-11}
& & \multicolumn{3}{c}{D} & \multicolumn{3}{c}{D} & \multicolumn{3}{c}{C} \\
\cmidrule(lr){3-5} \cmidrule(r){6-8} \cmidrule{9-11}
& &  O & T & N &   O & T & N &   O & T & N \\
\midrule

0-Function Hazards
 & $(0,1,0){\to}(1,1,1)$ & & \red & & & \red & \lime & & \red & \\ 
 & $(0,1,0){\to}(1,0,0)$ & & & \lime & & \red & \lime & & & \lime \\
 & $(1,1,1){\to}(1,0,0)$ & \red & & \lime & & & \lime & & \red & \\      
 & $(1,1,1){\to}(0,1,0)$ & & \lime & & & \lime & \red & & & \\
 & $(1,0,0){\to}(0,1,0)$ & \red & \lime & & & \lime & \red & \red & & \lime\\
 & $(1,0,0){\to}(1,1,1)$ & & \red & \lime & &\red & & & \red & \\
\addlinespace[2ex]

1-Function Hazards
& $(0,1,1){\to}(1,0,1)$ & & \lime & & \red & \lime & & \red & & \lime\\
& $(0,0,0){\to}(0,1,1)$ & \lime & \red & & \lime & \red & & \lime & & \\
& $(0,0,0){\to}(1,0,1)$ & & \lime & & & \lime & & & \lime & \red\\
& $(1,0,1){\to}(0,1,1)$ & & & & & \red& \lime & \lime & \red &  \\      
& $(0,1,1){\to}(0,0,0)$ & & \red & & \lime & \red  & & \lime & & \red\\
& $(1,0,1){\to}(0,0,0)$ & & \red & & & \red& \lime & \lime & \red & \\
\addlinespace[2ex]

Wrong Steady State
& $(0,0,0)$ & \lime & \red & & \lime & \red & & \lime & & \red\\
& $(0,0,1)$ & & \red & \lime & \lime & & \red & & \red & \lime\\
& $(0,1,0)$ & & \red & \lime & & & \lime & & \red &\lime \\
& $(0,1,1)$ & \lime & \red & & \lime & \red & & \lime & \red & \\     
& $(1,0,0)$ & & & \lime & & & \lime & \lime & & \\
& $(1,0,1)$ & & \red & & & \red & & \red & & \lime\\
& $(1,1,0)$ & & \red & \lime & \red & & & & \red & \\
& $(1,1,1)$ & & \red & \lime & & \red & \lime & \lime & \red & \\
\bottomrule
\end{tabular*}

\medskip
\footnotesize
This table compares each models' predictions for best and worst performance for each transition. A red color means that the circuit performed worse than the median, and green color means that the circuit performed better than the median, for that input molecule concentration or transition. \par
\end{table}
\end{document}

相关内容