1

I am looking for a way have white text on black background in the LaTeX applied to a document containing a basic table with dividing lines and some colored links.

Using this code as below. However I can not write the table as in the figure.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}
sporc
  • 643

2 Answers2

4

like this:

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}
Zarko
  • 296,517
  • ! Thanks a lot! How can I move the "Introduction" to the left of the table? and keep the "Introduction (Learning objectives)", etc at the center? – user3727281 Jul 27 '18 at 09:44
  • 1
    see edited answer. from your image in question i conclude, that contents in second columns is actually list. if this is so, consider to use itemize environment for it. for this see http://tex.stackexchange.com/questions/347253/ – Zarko Jul 27 '18 at 10:18
3

For comparison, such tables are much simpler to typeset in ConTeXt (but I don't know of any LaTeX package that has similar syntax). Notice that there is very separation of content and presentation.

\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

Aditya
  • 62,301