在一行中使用多个多列

在一行中使用多个多列

我正在尝试在表格的一行中创建多个带有彩色背景的带框单元格,每行使用多个多列。我希望彩色区域具有相同的大小(宽度)(3cm)。但不知何故,在一行中生成这些相同的、彩色的多列单元格似乎行不通。

谢谢

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{multirow, colortbl}
\usepackage{xcolor}
\usepackage{array}

\definecolor{Grey}{HTML}{808080}%define a color for tables - hex # gray

\begin{document}

\renewcommand\arraystretch{1.3}
\begin{tabular}%
{
>{\raggedleft\arraybackslash}
p{4cm}%
p{3cm}%
p{4cm}%
p{3cm}%
}
 &\\  \cline{2-2}  \cline{4-4} 
\textbf{Erstkontakt (Datum)}   &  \multicolumn{1}{|c|}{\cellcolor{Grey}}   &
\textbf{Projektnummer}   &   \multicolumn{1}{|c|}{\cellcolor{Grey}} \\ [6pt] \cline{2-2}  \cline{4-4} 
 \end{tabular}



\end{document} 

答案1

您的问题仍然不清楚...我怀疑您正在寻找类似这样的内容:

enter image description here

(红线表示页面布局,如您所见,表格比文本宽度宽)

母语:

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{booktabs}       % <-- not used
\usepackage{multirow}       % <-- changed
\usepackage[table]{xcolor}  % <-- changed

\definecolor{Grey}{HTML}{808080}%define a color for tables - hex # gray

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}

\renewcommand\arraystretch{1.3}
\noindent
    \begin{tabular}%
{
>{\raggedleft\arraybackslash}p{4cm}%
        >{\columncolor{Grey}}p{3cm}%
                             p{4cm}%
        >{\columncolor{Grey}}p{3cm}%
}
\textbf{Erstkontakt (Datum)}   &    &   \textbf{Projektnummer}   &      \\

在深灰色的细胞颜色中,边界线没有意义。

如果您的表格有多行并且只有一个单元格有彩色,那么您可以简单地这样写:

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{array}
\usepackage{booktabs}       % <-- not used
\usepackage{multirow}       % <-- changed
\usepackage[table]{xcolor}  % <-- changed

\definecolor{Grey}{HTML}{808080}%define a color for tables - hex # gray

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\begin{document}

\renewcommand\arraystretch{1.3}
\noindent
    \begin{tabular}%
{
>{\raggedleft\arraybackslash}p{4cm}
                             p{3cm}
                             p{4cm}
                             p{3cm}
}
\textbf{Erstkontakt (Datum)}   
    &   \cellcolor{Grey}   
        &   \textbf{Projektnummer}   
            &   \cellcolor{Grey}         \\
    \end{tabular}
\end{document}

答案2

我自己解决了:

\documentclass[11pt,a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{multirow, colortbl}
\usepackage{xcolor}
\usepackage{array}

\definecolor{Grey}{HTML}{808080}%define a color for tables - hex # gray

\begin{document}

\renewcommand\arraystretch{1.3}
\begin{tabular}%
{
>{\raggedleft\arraybackslash}
p{4cm}%
p{3cm}%
p{4cm}%
p{3cm}%
}
 &\\  \cline{2-2}  \cline{4-4} 
\textbf{Erstkontakt (Datum)}   &  \multicolumn{1}{|c|}{\cellcolor{Grey}}   &
\textbf{Projektnummer}   &   \multicolumn{1}{|c|}{\cellcolor{Grey}} \\ [6pt] \cline{2-2}  \cline{4-4} 
&&&\\
 \end{tabular}

\end{document} 

相关内容