如何制作这样的表格?

如何制作这样的表格?

所以我制作了两个表格,但格式有问题。那么如何在这些表格中留出空格以及如何将第一个表格与侧面的标题对齐?

第一张表

第二张表

    \begin{table}[]
\caption{DNA Encoding and Decoding Rule}
\label{tab:my-table}
\setlength{\tabcolsep}{0.5em} % for the horizontal padding
{\renewcommand{\arraystretch}{1.2}% for the vertical padding
\begin{tabular}{@{}lllll@{}}
\toprule
       & 00 & 10 & 01 & 11 \\ \midrule
Rule 1 & A  & C  & G  & T  \\
Rule 2 & A  & G  & C  & T  \\
Rule 3 & T  & G  & C  & A  \\
Rule 4 & T  & C  & G  & A  \\
Rule 5 & G  & A  & T  & C  \\
Rule 6 & G  & T  & A  & C  \\
Rule 7 & C  & A  & T  & G  \\
Rule 8 & C  & T  & A  & G  \\ \bottomrule
\end{tabular}
}
\end{table}



 \begin{table}[]
\caption{Mutation effect example}
\label{tab:my-table}
\resizebox{\columnwidth}{!}{%
\begin{tabular}{@{}lllll@{}}
\toprule
\begin{tabular}[c]{@{}l@{}}Original \\    \\ Number\end{tabular} & DNA sequence & Type of mutation & Mutated sequence & Number corresponding to mutated sequence \\ \midrule
237 & ‘TCTG’ & Deletion     & ‘TTG’   & 61  \\ \midrule
237 & ‘TCTG’ & Insertion    & ‘TCATG’ & 909 \\
237 & ‘TCTG’ & Substitution & ‘TCAG’  & 225 \\
237 & ‘TCTG’ & Duplication  & ‘TCTTG’ & 957
\end{tabular}%
}
\end{table}

答案1

我删除了第一个表格中的填充,并将标题放在剩余的空间中。我想你已经有了\captionsetup,所以没有必要尝试重现它。

对于第二张表,主要问题是尝试将最后一列放在页面上,并使用尽可能少的行。我使用了 tabularx,但只用于最后一列。

\documentclass{article}
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{showframe}% alignment tool
\begin{document}

\begin{table}[]
\sbox0{% measure width
\begin{tabular}[t]{@{}lllll@{}}
\toprule
       & 00 & 10 & 01 & 11 \\ \midrule
Rule 1 & A  & C  & G  & T  \\
Rule 2 & A  & G  & C  & T  \\
Rule 3 & T  & G  & C  & A  \\
Rule 4 & T  & C  & G  & A  \\
Rule 5 & G  & A  & T  & C  \\
Rule 6 & G  & T  & A  & C  \\
Rule 7 & C  & A  & T  & G  \\
Rule 8 & C  & T  & A  & G  \\ \bottomrule
\end{tabular}}%
\begin{minipage}[t]{\dimexpr \columnwidth-\wd0-\columnsep}
\abovecaptionskip=0pt
\caption{DNA Encoding and Decoding Rule}
\label{tab:my-table}
\end{minipage}\hfill\usebox0
\end{table} 

\begin{table}[]
\caption{Mutation effect example}
\label{tab:my-table}
\begin{tabularx}{\columnwidth}{@{}llllX@{}}
\toprule
\parbox[t]{4em}{Original Number} &
\parbox[t]{4em}{DNA\newline sequence} &
\parbox[t]{4em}{Type of mutation} &
\parbox[t]{4em}{Mutated sequence} &
Number corresponding to mutated sequence \\ \midrule
237 & ‘TCTG’ & Deletion     & ‘TTG’   & 61  \\ \midrule
237 & ‘TCTG’ & Insertion    & ‘TCATG’ & 909 \\
237 & ‘TCTG’ & Substitution & ‘TCAG’  & 225 \\
237 & ‘TCTG’ & Duplication  & ‘TCTTG’ & 957
\end{tabularx}%
\end{table}

\vfill\hrule% to avoid becoming [p] floats.
\end{document}

答案2

这个怎么样?我做了一些最简单的例子,并清理了一些我不清楚的东西。备注:

  • 请注意两件事:\begin{tabularx}{0.9\textwidth}{XXX}
  1. \begin{tabularx}{0.9\textwidth}将表格定义为文本宽度的 90%,你可以根据自己的喜好尝试一下
  2. 根据这个帖子例如,使用XXX三个均匀分布的列宽覆盖整个表格宽度
  • 我使用了tabularx-package。
  • 我有一些很好的经验来\hline获得水平线
  • 不知道左侧标题

最小示例:

\documentclass{article}
\usepackage{array}
\usepackage{tabularx}    
    
\begin{document}
\begin{table}[]
\caption{DNA Encoding and Decoding Rule}
\label{tab:my-table}
\begin{tabularx}{0.9\textwidth}{l X X X X }
\hline
       & 00 & 10 & 01 & 11 \\ \hline
Rule 1 & A  & C  & G  & T  \\
Rule 2 & A  & G  & C  & T  \\
Rule 3 & T  & G  & C  & A  \\
Rule 4 & T  & C  & G  & A  \\
Rule 5 & G  & A  & T  & C  \\
Rule 6 & G  & T  & A  & C  \\
Rule 7 & C  & A  & T  & G  \\
Rule 8 & C  & T  & A  & G  \\ \hline
\end{tabularx}
\end{table}



\begin{table}[]
\caption{Mutation effect example}
\label{tab:my-table}
\begin{tabularx}{0.9\textwidth}{XXXXX}
\hline
Original Number & DNA sequence & Type of mutation & Mutated sequence & Number corresponding to mutated sequence \\ \hline
237 & ‘TCTG’ & Deletion     & ‘TTG’   & 61  \\ 
237 & ‘TCTG’ & Insertion    & ‘TCATG’ & 909 \\
237 & ‘TCTG’ & Substitution & ‘TCAG’  & 225 \\
237 & ‘TCTG’ & Duplication  & ‘TCTTG’ & 957
\end{tabularx}
\end{table}
    
\end{document}

看起来像这样:

在此处输入图片描述

答案3

以下是实现每个表的输出的一些想法:

  1. \caption将内部的设置minipage为所需的宽度;这会将其装箱,允许您将其放置在另一个“盒子”旁边(如tabular)。

  2. 可以使用tabularx“扩展”,或预定的@{<space>}列分离。

  3. makecell还可以帮助在单元格中手动换行,以及特定于单元格的对齐规范。

在此处输入图片描述

\documentclass{article}

\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{booktabs,caption,tabularx,makecell}

\captionsetup[table]{%
  labelfont=bf,
  justification=raggedright,
  singlelinecheck=false
}

\begin{document}

\begin{table}
  \begin{minipage}[t]{.3\linewidth}
    \caption{DNA encoding and decoding Rule}
  \end{minipage}%
  \hfill
  \begin{tabular}[t]{ @{} l *{4}{ @{\hspace{4em}} c } @{} }
    \toprule
           & 00 & 10 & 01 & 11 \\
    \midrule
    Rule 1 &  A &  C &  G &  T \\
    Rule 2 &  A &  G &  C &  T \\
    Rule 3 &  T &  G &  C &  A \\
    Rule 4 &  T &  C &  G &  A \\
    Rule 5 &  G &  A &  T &  C \\
    Rule 6 &  G &  T &  A &  C \\
    Rule 7 &  C &  A &  T &  G \\
    Rule 8 &  C &  T &  A &  G \\
    \bottomrule
  \end{tabular}

  \bigskip

  \caption{Mutation effect example}
  \begin{tabularx}{\columnwidth}{@{} l @{\qquad} *{4}{X} @{}}
    \toprule
    \makecell[t]{Original \\ Number} &
    DNA sequence &
    Type of mutation &
    Mutated sequence &
    \raggedright\arraybackslash Number corresponding to mutated sequence \\
    \midrule
    237 & `TCTG' & Deletion     & `TTG'   & 61  \\
    237 & `TCTG' & Insertion    & `TCATG' & 909 \\
    237 & `TCTG' & Substitution & `TCAG'  & 225 \\
    237 & `TCTG' & Duplication  & `TCTTG' & 957 \\
    \bottomrule
  \end{tabularx}
\end{table}

\end{document}

有关表格中间距的更多相关概念,请参阅表格中的列和行填充

相关内容