0

I'm trying to color the title line of the table by using the following code:

\documentclass[a4paper, 10pt]{article}

%% Packages %%
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{fancyhdr}
\usepackage{tikz,float}
\usetikzlibrary{shapes,arrows}
\usepackage{verbatim}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{tabu}
\usepackage{sidecap}
\usepackage{multirow}
\usepackage[sorting=none]{biblatex}
\usepackage{subcaption}
\usepackage{setspace}
\usepackage{multicol}
\usepackage{scalerel}
\usepackage{enumitem}
\usepackage{empheq}
\usepackage{caption}
\usepackage{float}
\usepackage{kantlipsum}
\usepackage{xcolor,colortbl}
\usepackage{mathtools}
\usepackage{listings}
\usepackage[document]{ragged2e}
\setcounter{MaxMatrixCols}{20}
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
%% Title Page %%

\addbibresource{refbib.bib}

\begin{document}

\begin{table}[htbp]
\begin{center}
{\tabulinesep=1.2mm 
    \begin{tabu} to 0.9\linewidth { |[2pt] *{3}{X[1 c]|}[2pt] } \tabucline[2pt]{-}
        \multicolumn{3}{ |[2pt]c|[2pt] }{\cellcolor{green!20}Initial Conditions} \\ \tabucline[2pt]{-}
        $[x(0), y(0), z(0)]_{\text{R}}$ & [-29136.9, 0, 0] & m \\ \hline
        $[x(0), y(0), z(0)]_{\text{T}}$ & [0, 0, 0] & m \\ \hline   
        $[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{R}}$ & [680.7, 0, 680.7] & m/s \\ \hline
        $[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{Wind}}$ & [0, -10, 0] & m/s \\ \hline
        $[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{Wind Error}}$ & [0, 0, 0] & m/s \\ \hline
        Launch Angle & 45 & Deg \\ \tabucline[2pt]{-}
    \end{tabu}}
\end{center}
\caption{Initial conditions for test 1}
\end{table}
\end{document}

However, for some reason I still get this result:

enter image description here

Is there a reason that it doesn't show the line in green?

Thank you

  • Can you post your preamble part, i.e., from \documentclass to \begin{document}? – MadyYuvi Jan 7 at 8:33
  • BTW, your code works fine, Green color comes for the first row... – MadyYuvi Jan 7 at 8:37
  • For me, it doesn't work some why =S, added what you asked. – Ben Jan 7 at 8:47
  • 2
    I can confirm your findings. BTW, use of tabu package can be problematic, It is not maintained and contain bugs. Also not work well with [table]{xcolor} etc. I suggest you use tabularx instead of it. – Zarko Jan 7 at 9:13
  • 1
    @Zarko it doesn't work because of the use of tabu. That is one of the open bug github.com/tabu-issues-for-future-maintainer/tabu/issues/13. – Ulrike Fischer Jan 7 at 10:12
2

I would not use the tabu package for my tables. IUnfortunately this package with attractive intentions is buggy (especially after new version of array` package on which it is based) and not maintained.

For your table seems to be more appropriate to use ordinary tabular environment, not lock cells' content in "prison of horizontal and vertical tables' rules, left align cells' n. For more vertical space I would use of the cellspace package:

enter image description here

\documentclass[a4paper, 10pt]{article}
\usepackage[top=1in, bottom=1in, left=1in, right=1in]{geometry}
\usepackage{mathtools}
\usepackage[skip=1ex]{caption}
\usepackage[table]{xcolor}
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\usepackage{cellspace, makecell, tabularx}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}


\begin{document}
    \begin{table}[htbp]
    \centering
\caption{Initial conditions for test 1}
\label{my table}
    \begin{tabular}{ *{2}{>{$}Sl<{$}} l } 
    \Xhline{1pt}
    \rowcolor{mygreen!20}
\multicolumn{3}{Sc}{Initial Conditions}     \\ 
    \Xhline{0.75pt}
{[x(0), y(0), z(0)]_{\mathrm{R}}}   
        & [-29136.9, 0, 0]      & m         \\  
{[x(0), y(0), z(0)]_{\text{T}}}     
        & [0, 0, 0]             & m         \\
{[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{R}}}
    & [680.7, 0, 680.7]         & m/s       \\ 
{[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{Wind}}}
    & [0, -10, 0]               & m/s       \\ 
{[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{Wind Error}}}
    &  [0, 0, 0]                & m/s       \\ 
\text{Launch Angle}             
    & 45                        & Degrees   \\ 
    \Xhline{1pt}
    \end{tabular}
    \end{table}
\end{document}

**Addendum:**The same table with use of the siunitx package. Use their names for units make their use more clear ... and hopefully encourage you to use it for all units in your document:

\documentclass[a4paper, 10pt]{article}
\usepackage[margin=1in]{geometry}
\usepackage[skip=1ex]{caption}
\usepackage[table]{xcolor}
\definecolor{mygreen}{RGB}{28,172,0} % color values Red, Green, Blue
\definecolor{mylilas}{RGB}{170,55,241}
\usepackage{cellspace, makecell, tabularx}
\setlength\cellspacetoplimit{5pt}
\setlength\cellspacebottomlimit{5pt}
\usepackage{siunitx}

\begin{document}
    \begin{table}[htbp]
    \centering
    \sisetup{per-mode=symbol}
\caption{Initial conditions for test 1}
\label{my table}
    \begin{tabular}{ *{2}{>{$}Cl<{$}} s } 
    \Xhline{1pt}
    \rowcolor{mygreen!20}
\multicolumn{3}{Cc}{Initial Conditions}             \\ 
    \Xhline{0.6pt}
{[x(0), y(0), z(0)]_{\mathrm{R}}}   
        & [-29136.9, 0, 0]      & \metre            \\  
{[x(0), y(0), z(0)]_{\text{T}}}     
        & [0, 0, 0]             & \metre            \\
{[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{R}}}
    & [680.7, 0, 680.7]         & \metre/\second    \\ 
{[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{Wind}}}
    & [0, -10, 0]               & \metre\per\second \\ 
{[V_{x}(0), V_{y}(0), V_{z}(0)]_{\text{Wind Error}}}
    &  [0, 0, 0]                & \metre\per\second \\ 
\text{Launch Angle}             
    & 45                        & Degrees   \\ 
    \Xhline{1pt}
    \end{tabular}
    \end{table}
\end{document}

Result is the same as it is at the first example.

  • Why not also add siunitx for the units in the last column? – leandriis Jan 7 at 11:45
  • 1
    @leandriis, good question! OP use a lot of different packages but not siunitx (what one can expected, since table deals with units). The table background is unknown, I miss column headers (what means values in each column), etc Anyway I will add a table version with use of siunitx, that OP will be aware for the siunitx package. – Zarko Jan 7 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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