0

I need help centering horizontally the text in the dates/terms header in my table I created using tabularx. The text in the first column shouldn't be centered. I've tried multiple ways, but every way I try I either lose the two different column spacings and all columns end up as the same width or I end up with empty space to the right of the table (though the table should fill the entire width of text). Also, I can't seem to figure out why some of the vertical lines are darker than others. If you could help with that, too, much appreciated. Thank you for your help!

\documentclass{article}
\usepackage[utf8]{inputenc}


\usepackage{tabularx}
\usepackage[table]{xcolor}
\usepackage{float}
\usepackage{ragged2e}
\usepackage{array}
\usepackage{booktabs}



\begin{document}

\newcolumntype{s}{>{\hsize=0.5\hsize}X}
\newcolumntype{b}{>{\hsize=5.5\hsize}X}


\begin{center}
\begin{scriptsize}
\begin{tabularx}{\textwidth}{| b | s | s | s | s | s | s | s | s | s | s | s |}

\cline{2-12}
\multicolumn{1}{b|}{} & \multicolumn{1}{s|}{2018} & \multicolumn{3}{s|}{2019} & \multicolumn{3}{s|}{2020} & \multicolumn{3}{s|}{2021} & \multicolumn{1}{s|}{2022} \\
\cline{2-12}
\multicolumn{1}{b|}{} &  Fall & Spr & Sum &  Fall & Spr & Sum &  Fall & Spr & Sum &  Fall & Spr \\

\hline
 asdfasdfasdf   & \cellcolor[rgb]{0.2,0.4,0.8}  &\cellcolor[rgb]{0.2,0.4,0.8}  & \cellcolor[rgb]{0.2,0.4,0.8}  &\cellcolor[rgb]{0.2,0.4,0.8}  &\cellcolor[rgb]{0.2,0.4,0.8}  &\cellcolor[rgb]{0.2,0.4,0.8}  &  & & &  &  \\
 \cline{1-1}
asdfasdfasdfasdfasdfasdf & \cellcolor[rgb]{0.2,0.4,0.8}  &  &  & & &  &  &  &  &  &  \\
\cline{1-1}
  asdfasdfasdfasdfasdfadsf & \cellcolor[rgb]{0.2,0.4,0.8}  & \cellcolor[rgb]{0.2,0.4,0.8}   & \cellcolor[rgb]{0.2,0.4,0.8}   &  &  &  & &  &  &  &  \\
\cline{1-1}
 asdfasdfasdasdfasdfadsfasdff &  & \cellcolor[rgb]{0.2,0.4,0.8}  & \cellcolor[rgb]{0.2,0.4,0.8}  & \cellcolor[rgb]{0.2,0.4,0.8}  & \cellcolor[rgb]{0.2,0.4,0.8}  & \cellcolor[rgb]{0.2,0.4,0.8}   &  &  & &  &  \\
 \cline{1-1}
 asdfasasdfadsfasdfdfasdf  & \cellcolor[rgb]{0.8,0.4,0.3} & \cellcolor[rgb]{0.8,0.4,0.3} & \cellcolor[rgb]{0.8,0.4,0.3} & \cellcolor[rgb]{0.8,0.4,0.3} & \cellcolor[rgb]{0.8,0.4,0.3} & \cellcolor[rgb]{0.8,0.4,0.3} &  &  &  &  &  \\
 \cline{1-1}
 asdfasdfasdfasdfasdfasdfasdf & \cellcolor[rgb]{0.8,0.4,0.3} &  &  &  &  &  &  &  &  & &  \\
 \cline{1-1}
 asdfasdfasdfasdfasdfafds &  & \cellcolor[rgb]{0.8,0.4,0.3} & &  &  &  &  &  &  &  & \\

\hline
\end{tabularx}
\end{scriptsize}
\end{center}

\end{document}
  • Welcome to TeX SX! I think you've misunderstood how one calculates the coefficients. The large X column (1st column) should be approximately how many times a small one? – Bernard Jul 31 '18 at 0:16
  • Thanks for the response. About six times larger than a single small column. – lpuppy79 Jul 31 '18 at 0:49
0

Here is a code that works. You should keep in mind that, in case of X columns of different widths (with \hsize=some coefficient \hsize), the total of the coefficients has to be equal to the total number of X type columns;

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{array}\usepackage{tabularx}
\usepackage[table]{xcolor}
\definecolor{myblue}{rgb}{0.2,0.4,0.8}
\definecolor{myred}{rgb}{0.8,0.4,0.3}
\newcolumntype{s}{>{\hsize=0.7\hsize\centering\arraybackslash}X}
\newcolumntype{b}{>{\hsize= 4.3\hsize\arraybackslash}X}

\begin{document}

\begin{center}
\setlength{\tabcolsep}{3pt}
\setlength{\extrarowheight}{2pt}
\begin{scriptsize}
\begin{tabularx}{\textwidth}{| b|*{11}{s|}}
\cline{2-12}
\multicolumn{1}{b|}{} & \multicolumn{1}{c|}{2018} & \multicolumn{3}{c|}{2019} & \multicolumn{3}{c|}{2020} & \multicolumn{3}{c|}{2021} & \multicolumn{1}{c|}{2022} \\
\cline{2-12}
\multicolumn{1}{b|}{} & Fall & Spr & Sum & Fall & Spr & Sum & Fall & Spr & Sum & Fall & Spr \\
\hline
 asdfasdfasdf & \multicolumn{1}{c|}{\cellcolor{myblue}} &\cellcolor{myblue} & \cellcolor{myblue} &\cellcolor{myblue}&\cellcolor{myblue} &\cellcolor{myblue} & & & & & \\
 \cline{1-1}
asdfasdfasdfasdfasdfasdf & \multicolumn{1}{c|}{\cellcolor{myblue}} & & & & & & & & & & \\
\cline{1-1}
  asdfasdfasdfasdfasdfadsf & \multicolumn{1}{c|}{\cellcolor{myblue}} & \cellcolor{myblue} & \cellcolor{myblue} & & & & & & & & \\
\cline{1-1}
 asdfasdfasdasdfasdfadsfasdff & & \cellcolor{myblue} & \cellcolor{myblue} & \cellcolor{myblue} & \cellcolor{myblue} & \cellcolor{myblue} & & & & & \\
 \cline{1-1}
 asdfasasdfadsfasdfdfasdf & \multicolumn{1}{c|}{\cellcolor{myred}} & \cellcolor{myred} & \cellcolor{myred} & \cellcolor{myred} & \cellcolor{myred} & \cellcolor{myred} & & & & & \\
 \cline{1-1}
 asdfasdfasdfasdfasdfasdfasdf & \multicolumn{1}{c|}{\cellcolor{myred}} & & & & & & & & & & \\
 \cline{1-1}
 asdfasdfasdfasdfasdfafds & & \cellcolor{myred} & & & & & & & & & \\
\hline
\end{tabularx}
\end{scriptsize}
\end{center}

\end{document} 

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.