更改表格单元格宽度

更改表格单元格宽度

在此处输入图片描述

我想在乳胶中复制这个,其中底行的单元格不如顶部的其他单元格宽,到目前为止我的代码和输出是:

\begin{center}
\begin{tabular}{|l | p{13cm}|}
\hline
    {Tested By} & {SQA Team}\\    
\hline
    {Test Type} & {Acceptance Test}\\    
\hline
    {Test Case Number} & {TC-1.1 Create a client successfully}\\    
\hline
    {Test Case Description} & {This test case is used to check if a visitor can create a client with the system}\\    
\hline
    \multicolumn{2}{|c|}{Item(s) to be tested}\\
\hline
    {1.} & {SRS 3.1.1.1}\\    
\hline


\end{tabular}
\end{center}

导致:

在此处输入图片描述

答案1

单程 :

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}
\usepackage[frenchb]{babel}
\usepackage{array}
\usepackage[table,x11names]{xcolor}
\usepackage{colortbl}
\usepackage[a4paper, margin={1cm,1cm}]{geometry}

\begin{document}
\begin{center}
\begin{tabular}{|ll| p{13cm}|}
\hline
\multicolumn{2}{|l|}{\cellcolor{Gray0}Tested By} & {SQA Team}\\
\hline
\multicolumn{2}{|l|}{\cellcolor{Gray0}Test Type} & {Acceptance Test}\\    
\hline
\multicolumn{2}{|l|}{\cellcolor{Gray0}Test Case Number} & {TC-1.1 Create a client successfully}\\    
\hline
  \multicolumn{2}{|l|}{\cellcolor{Gray0}Test Case Description} & {This test case is used to check if a visitor can create a client with the system}\\    
\hline
  \multicolumn{3}{|c|}{\cellcolor{Gray0}Item(s) to be tested}\\
\hline
1.\hspace{1cm} & \multicolumn{2}{|l|}{\fcolorbox{white}{DeepSkyBlue1}{SRS 3.1.1.1}}\\    
\hline


\end{tabular}
\end{center}
\end{document}

在此处输入图片描述

答案2

\makebox有多种方法可以实现这一点。我偏爱使用和来伪造最后一行\vrule

\documentclass{article}
\usepackage[a4paper, margin={1cm,1cm}]{geometry}

\newcommand{\myrow}[2]% #1=first column, #2=second column
{\multicolumn{2}{|l|}{\makebox[1cm][l]{#1}\hspace{\tabcolsep}\vrule\hspace{\tabcolsep}#2}}

\begin{document}
\begin{center}
\begin{tabular}{|l | p{13cm}|}
\hline
    {Tested By} & {SQA Team}\\    
\hline
    {Test Type} & {Acceptance Test}\\    
\hline
    {Test Case Number} & {TC-1.1 Create a client successfully}\\    
\hline
    {Test Case Description} & {This test case is used to check if a visitor can create a client with the system}\\    
\hline
    \multicolumn{2}{|c|}{Item(s) to be tested}\\
\hline
    \myrow{1.}{SRS 3.1.1.1 }\\
\hline
\end{tabular}
\end{center}
\end{document}

演示

答案3

另一种选择是认为有三列;在第 1-4 行中,第一列跨越两列,在第 5 行以后,第二列跨越两列。以下是在 ConTeXt 中实现此操作的方法(该解决方案应该很容易移植到 LaTeX):

\startsetups testing
  \setupTABLE[toffset=0.5ex, boffset=0.5ex]
  \setupTABLE[column][1][width=4em]
  \setupTABLE[column][2][width=6em]
  \setupTABLE[column][3][width=broad]

  \setupTABLE[1,2][1,2,3,4][background=color, backgroundcolor=gray]
  \setupTABLE[row][5][align=middle, background=color, backgroundcolor=gray]
\stopsetups

\starttext
\startTABLE[setups=testing]
  \NC[nc=2] Tested By \NC SQA Team \NC \NR
  \NC[nc=2] Test Type \NC Acceptance Test \NC \NR
  \NC[nc=2] Test Case Number \NC TC-1.1 Create a client successfully \NC \NR
  \NC[nc=2] Test Case Description \NC This test case is used to check if a visitor can create a client with the system \NC \NR
  \NC[nc=3] Item(s) to be tested \NC \NR
  \NC 1. \NC[nc=2] SRS 3.1.1.1 \NC \NR
\stopTABLE
\stoptext

在此处输入图片描述

相关内容