Reputation: 1570
Inmy table below I have six months divided into weeks. I have been trying to have vertical lines only on the 4th, 8th, 12th, 16th, 20th an 24th week, i.e. every month only, or make every 4th vertical line thicker, without any success. Is this possible. Or my searches on stackoverflow have not worked for me. I will appreciate any help.
\documentclass[11pt,twoside,fleqn]{report}
\usepackage{array,booktabs,tabularx} % also loads 'array' package
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of 'X' columns
\usepackage{ltablex}
\usepackage{longtable}
\usepackage[svgnames,table]{xcolor} % Required to specify font color
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.2}
\begin{document}
\begin{longtable}[H]{|p{3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} |p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm}|p{0.3cm}|p{0.3cm}|p{0.3cm} | p{0.3cm} | p{0.3cm}|}
\hline
\setlength{\tabcolsep}{2pt} % for the horizontal padding
\renewcommand{\arraystretch}{2}% for the vertical padding
\textbf{first entires} &\cellcolor{orange} &\cellcolor{orange} &\cellcolor{orange} &\cellcolor{orange} & & & & & & & & & & & & & & & & & & & &
\\[0.10cm]
\hline
\textbf{second entries} & & & & & & & & & \cellcolor{blue}&\cellcolor{blue} &\cellcolor{blue} &\cellcolor{blue} & & & & & & & & & & & &
\\[0.10cm]
\hline
\textbf{third entries} & & & & & & & & && & & & \cellcolor{orange}& \cellcolor{orange} & \cellcolor{orange} & \cellcolor{orange} & & & & & & & &
\\[0.10cm]
\hline
\textbf{End} & & & & & & & & & & & & & & & & & & & & & & &\cellcolor{teal} &\cellcolor{teal}
\\[0.10cm]
\hline
\bottomrule
\end{longtable}
\end{document}
Upvotes: 1
Views: 6642
Reputation: 11567
To avoid having a vertical bar, you just have to drop the '|' specifier from this column. From your original example, this could be done by
\begin{longtable}[H]{|p{3cm} |
%p{0.3cm} | p{0.3cm} | p{0.3cm} | p{0.3cm} |
p{0.3cm} p{0.3cm} p{0.3cm} p{0.3cm} |
p{0.3cm} p{0.3cm} p{0.3cm} p{0.3cm} |
p{0.3cm} p{0.3cm} p{0.3cm} p{0.3cm} |
p{0.3cm} p{0.3cm} p{0.3cm} p{0.3cm} |
p{0.3cm} p{0.3cm} p{0.3cm} p{0.3cm} | }
But such a method is error prone for a 25 columns table and you should prefer the *
modifiers. *{num}{cells format}
will repeat num time a given format list and these commands can be nested.
So for you problem, you have 6 months of 4 weeks and this can be given as
\begin{longtable}[H]{ |p{3cm} | *6{*4{p{0.3cm}}|} }
with only a vertical bar at the end of a month.
To have different width of vertical bars,
it is possible to use the '!' separator specifier. In tabular, any vertical bar can be replaced by a !{<separator command or char>}
. This command is a full replacement for |
and do not modify column spacing.
The TeX primitive \vrule
must be used and vrule width <w>
will draw a vertical rule of width <w>
and of an height given by the enclosing box.
\documentclass[11pt,twoside,fleqn]{report}
\usepackage{array,tabularx} % also loads 'array' package
\usepackage{booktabs}
\newcolumntype{C}{>{\centering\arraybackslash}X} % centered version of 'X' columns
\usepackage{ltablex}
\usepackage{longtable}
\usepackage[svgnames,table]{xcolor} % Required to specify font color
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{3pt}
\renewcommand{\arraystretch}{1.2}
\begin{document}
{
\setlength\arrayrulewidth{2pt}
\newcommand{\thinvrule}{{\vrule width 0.5pt}}
\renewcommand{\arraystretch}{2}% for the vertical padding
\renewcommand{\defaultaddspace}{1cm}
\setlength{\tabcolsep}{2pt} % for the horizontal padding
\begin{longtable}[H]{|p{3cm} | *6{*3{p{0.3cm}!\thinvrule }p{0.3cm}|}}
\hline
\textbf{first entires} &\cellcolor{orange} &\cellcolor{orange} &\cellcolor{orange} &\cellcolor{orange} & & & & & & & & & & & & & & & & & & & &
\\[0.10cm]
\hline
\textbf{second entries} & & & & & & & & & \cellcolor{blue}&\cellcolor{blue} &\cellcolor{blue} &\cellcolor{blue} & & & & & & & & & & & &
\\[0.10cm]
\hline
\textbf{third entries} & & & & & & & & && & & & \cellcolor{orange}& \cellcolor{orange} & \cellcolor{orange} & \cellcolor{orange} & & & & & & & &
\\[0.10cm]
\hline
\textbf{End} & & & & & & & & & & & & & & & & & & & & & & &\cellcolor{teal} &\cellcolor{teal}
\\[0.10cm]
\hline
\bottomrule
\end{longtable}
}
\end{document}
EDIT: To add a column with the month name, you can use the '\multicolumn` command. To spread over number columns, its syntax is
\multicolumn{number}{format}{content}
So for your problem, add before the first \hline
\hline
&\multicolumn{4}{c|}{jan}&\multicolumn{4}{c|}{feb}&\multicolumn{4}{c|}{mar}&\multicolumn{4}{c|}{apr}&\multicolumn{4}{c|}{may}&\multicolumn{4}{c|}{jun}\\
Upvotes: 3