在表格中的黑色和灰色背景上制作白色文字?

在表格中的黑色和灰色背景上制作白色文字?

我正在寻找一种方法,将 LaTeX 中的黑色背景上白色文本应用于包含带有分隔线和一些彩色链接的基本表格的文档。

使用下面的代码。但是我无法像图中这样写表格。enter image description here

\documentclass[a4paper, 10pt]{article}
\usepackage[a4paper]{geometry}
\usepackage[table]{xcolor}
\usepackage{array}
\begin{document}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcolumntype{B}{>{\columncolor{black}\color{white}}c}
\newcolumntype{E}{>{\columncolor{black}\color{white}}l}
\newcolumntype{P}[1]{>{\columncolor{black}\hspace{0pt}\color{white}}p{#1}}

\section{SCHEDULE (AT CLASS)}
\vspace{-0.5cm}
\begin{center} 
\begin{longtable}{|C{1.0cm}|C{7.0cm}|C{4.1cm}|C{4.0cm}|} 
\hline
\textbf{(Number Week)}   & \multicolumn{1}{c|}{\textbf{Introduction (Learning objectives)}} & \textbf{Class (Teaching Strategies)} & \textbf{Keypoint
(Student Activities)} \\
\hline
1 & \textbf{Chapter 0: Introduction about the important in this book} &   &   \\
\hline
1  & - Introduction    &   &   \\
\hline
\end{longtable}
%\end{tabular}
\end{center}

\end{document}

答案1

像这样:

enter image description here

\documentclass[a4paper, 10pt]{article}
\usepackage[a4paper, margin=20mm]{geometry}
\usepackage[table]{xcolor}
\usepackage{longtable}
\newcolumntype{L}[1]{>{\raggedright\arraybackslash}p{#1}}
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\newcolumntype{R}[1]{>{\raggedleft\arraybackslash}p{#1}}
\newcommand\bcwt[1]{%black cells white text   <--- new
    \cellcolor{black}\bfseries\textcolor{white}{#1}}

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

\begin{document}
\section{SCHEDULE (AT CLASS)}
{
\setlength\extrarowheight{2pt}
\begin{longtable}{| C{\dimexpr2cm-2\tabcolsep-1.25\arrayrulewidth\relax} | 
                    L{\dimexpr6cm-2\tabcolsep-1.25\arrayrulewidth\relax} | 
               *{2}{L{\dimexpr4.5cm-2\tabcolsep-1.25\arrayrulewidth\relax} |}
                  }
\hline
\bcwt{(Number Week)}
    &   \multicolumn{1}{C{\dimexpr6cm-2\tabcolsep-1.25\arrayrulewidth\relax}}%
        {\hfil\bcwt{Introduction\newline (Learning objectives)}}
        &   \multicolumn{1}{C{\dimexpr4.5cm-2\tabcolsep-1.25\arrayrulewidth\relax}}%
            {\hfil\bcwt{Class\newline  (Teaching Strategies)}}
            &   \multicolumn{1}{C{\dimexpr4.5cm-2\tabcolsep-1.25\arrayrulewidth\relax}}%
                {\hfil\bcwt{Keypoint\newline (Student Activities)}}   \\

    \hline
    \rowcolor{gray!30}
1 & \multicolumn{3}{l|}{\textbf{Chapter 0: Introduction about the important in this book}}   \\
    \hline
1  & - Introduction    &    &   \\
\hline
\end{longtable}
}
\end{document}

答案2

相比之下,在 ConTeXt 中排版此类表格要简单得多(但我不知道有任何 LaTeX 包具有类似的语法)。请注意,内容和表示非常分离。

\setupbodyfont[10pt]
\setupxtable[header]
            [
              align=middle,
              background=color,
              backgroundcolor=black,
              foregroundcolor=white,
            ]

\setupxtable[chapter]
            [
              background=color,
              backgroundcolor=gray,
              foregroundstyle=bold,
            ]

\setupxtable[content]
            [
              foregroundstyle=slanted,
              align=lohi,
            ]
\starttext

\startxtable[option=stretch]
  \startxrow[header]
    \startxcell Week \stopxcell
    \startxcell (Learning objectives) \stopxcell
    \startxcell (Teaching Startegies) \stopxcell
    \startxcell (Student Activities)  \stopxcell
  \stopxrow
  \startxrow[chapter]
    \startxcell[align=middle] 1 \stopxcell
    \startxcell[nx=3] Chapter 0: Introduction \stopxcell
  \stopxrow
  \startxrow[content]
    \startxcell \stopxcell
    \startxcell
      \startitemize[2,packed]
        \item Introduction
        \item Presentation
        \item Discussion
        \item Exercises
      \stopitemize
    \stopxcell
    \startxcell 
      Introduction \\ 
      Presentation
    \stopxcell
    \startxcell 
      Introduction \\ 
      Presentation
    \stopxcell
  \stopxrow
  \startxrow[chapter]
    \startxcell[align=middle] 1 \stopxcell
    \startxcell[nx=3] Chapter 1: Profiles \stopxcell
  \stopxrow
  \startxrow[content]
    \startxcell \stopxcell
    \startxcell
      \startitemize[2,packed]
        \item Introduction
        \item Presentation
        \item Discussion
        \item Exercises
      \stopitemize
    \stopxcell
    \startxcell 
      Introduction \\ 
      Presentation
    \stopxcell
    \startxcell 
      Introduction \\ 
      Presentation
    \stopxcell
  \stopxrow

\stopxtable

\stoptext

enter image description here

相关内容