Is there any way in latex to scan a cell of a table with horizontal, vertical, diogonal with lines?
I want similar thing as in below figure.
Thanks.
tables
Is there any way in latex to scan a cell of a table with horizontal, vertical, diogonal with lines?
I want similar thing as in below figure.
Thanks.
Here is one way following your idea of inserting a narrow, empty "dummy" column @{}p{...}@{}
:
\documentclass{article}
\usepackage[margin=.5in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
\noindent\small
\begin{tabularx}{\linewidth}{
>{\raggedleft\arraybackslash}X% column 1
*{5}{>{\centering\arraybackslash}p{.08\linewidth}}% columns 2-6
@{}p{1em}@{}% column 7
*{3}{>{\centering\arraybackslash}p{.08\linewidth}}}% columns 8-10
\toprule
Dependent Variable: &
\multicolumn{5}{c}{Dep.\ Var.\ =\ \textit{HoursWorked}} &&
\multicolumn{3}{c}{Dep.\ Var.\ =\ \textit{NumCommunications}} \\
\cmidrule{2-6}\cmidrule{8-10}
Model: &
(1) & (2) & (3) & (4) & (5) &&
(6) & (7) & (8) \\
\cmidrule{2-6}\cmidrule{8-10}
&&&&&&&&& \\
\bottomrule
\end{tabularx}
\end{document}
Here is another where you specify the column separation as a gap @{...}
, and cut horizontal line a bit short:
\documentclass{article}
\usepackage[margin=.5in]{geometry}% http://ctan.org/pkg/geometry
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}
\noindent\small
\begin{tabularx}{\linewidth}{
>{\raggedleft\arraybackslash}X% column 1
*{5}{>{\centering\arraybackslash}p{.08\linewidth}}% columns 2-6
@{\hspace{1em}}% column 6-7 gap
*{3}{>{\centering\arraybackslash}p{.08\linewidth}}}% columns 7-9
\toprule
Dependent Variable: &
\multicolumn{5}{c}{Dep.\ Var.\ =\ \textit{HoursWorked}} &
\multicolumn{3}{c}{Dep.\ Var.\ =\ \textit{NumCommunications}} \\
\cmidrule(r{1em}){2-6}\cmidrule{7-9}
Model: &
(1) & (2) & (3) & (4) & (5) &
(6) & (7) & (8) \\
\cmidrule(r{1em}){2-6}\cmidrule{7-9}
&&&&&&&& \\
\bottomrule
\end{tabularx}
\end{document}
In both instances I've used booktabs
and tabularx
to draw and stretch the table. geometry
was added to fit the table inside the margins. It may not be necessary for your end-use document.
This happens because colortbl
draws the rows over the columns.
Adopt this trick.
Add the following lines in your preamble:
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@classz}
{\CT@row@color}
{\oldCT@column@color}
{}
{}
\patchcmd{\@classz}
{\CT@column@color}
{\CT@row@color}
{}
{}
\patchcmd{\@classz}
{\oldCT@column@color}
{\CT@column@color}
{}
{}
\makeatother
MWE (I've changed your custom colors)
\documentclass[10pt,a4paper]{report}
\usepackage{colortbl}
\usepackage{xcolor}
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@classz}
{\CT@row@color}
{\oldCT@column@color}
{}
{}
\patchcmd{\@classz}
{\CT@column@color}
{\CT@row@color}
{}
{}
\patchcmd{\@classz}
{\oldCT@column@color}
{\CT@column@color}
{}
{}
\makeatother
\begin{document}
\begin{table}[h]
\begin{tabular}{|l|p{7cm}|}
\hline
\rowcolor{gray}
\textcolor{white}{\textit{Column 1}} & \textcolor{white}{\textit{Column 2}} \\ \hline
Fooo -- Bar & Some text here with enum:
\begin{itemize}
\item Item1
\item Item2
\item ...
\end{itemize} \\ \hline
\rowcolor{lightgray}
Foo -- Baar & Some text here.... \\ \hline
Fooo -- Baaaar & Some other text here \\ \hline
\rowcolor{lightgray}
Baar -- FOOO & Nope
\begin{itemize}
\item Item1
\end{itemize} \\ \hline
\end{tabular}
\end{table}
\end{document}
Output:
Best Answer
Something like this.
matrix of nodes
is used where atable
style is defined then each node can have its own pattern given with coloring capability. A special pattern calledmixed
is defined as a macro taking two cell-position argumentsCode