2

Why I got an extra navy space to the left in the header of the table?

Also, I want the diagonal line to be fit properly, any help.

\documentclass[a4paper,12pt]{article}

\usepackage{pict2e}
\usepackage[svgnames,  table, x11names]{ xcolor}%
\usepackage{caption, tabularx,  booktabs,  hhline}
\usepackage{diagbox, eqparbox, hhline}
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{20pt}
\renewcommand{\arraystretch}{1.5}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}

\begin{document}

\rowcolors{2}{PowderBlue!50}{PowderBlue!25} 
\begin{table}[H]
\centering
\caption{Decreasing percentage in amplitude}
\medskip
\label{tab:amplitude decreasing percentage}
\begin{tabular}[H]{>{\hspace{-1\tabcolsep}} *{6} {>{$}c<{$}}<{\hspace{-1\tabcolsep}}}
\rowcolor{Navy!80} \toprule
\textbf{\diagbox[height=8ex, width=4.5cm]{\raisebox{0.1\height}{\enspace\color{white}variables}}{ \raisebox{-1.5\height}{\, \color{white}$\Phi$}}}
& \color{white} 0.1\% &\color{white} 0.5\% &\color{white} 1\% & \color{white}1.5\% & \color{white}2\% \\ \midrule
x   &   3.34    &   16.19   &   31.11   &   44.65   &   56.77  \\ 
y  & 3.23   &   15.73   &   30.38 & 43.79    & 55.91 \\
\dot{x} & 3.36  &   16.2     &  31.09    &  44.61    &  56.80   \\
\dot{y} & 3.23  &   15.73    &  30.38    &  43.77    &  55.91 \\ 
\bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

1
  • @JohnKormylo > can be used, just that the argument is incorrect here as shown in Bernard's answer. Commented Mar 18, 2017 at 7:44

2 Answers 2

5

The faulty was your >{\hspace{-1\tabcolsep}}. I took the opportunity to use siunitx to align numbers on the decimal dot and simplify the code:

\documentclass[a4paper,12pt]{article}

\usepackage{pict2e}
\usepackage{amsmath}
\usepackage[svgnames, table, x11names]{ xcolor}%
\usepackage{caption, tabularx, booktabs, hhline}
\usepackage{diagbox, eqparbox, hhline}
\setlength{\arrayrulewidth}{0.5mm}
\setlength{\tabcolsep}{20pt}
\renewcommand{\arraystretch}{1.5}
\setlength{\aboverulesep}{0pt}
\setlength{\belowrulesep}{0pt}
\usepackage{siunitx}
\sisetup{table-number-alignment=center}

\begin{document}

\rowcolors{2}{PowderBlue!50}{PowderBlue!25}
\begin{table}
\centering
\caption{Decreasing percentage in amplitude}
\medskip
\label{tab:amplitude decreasing percentage}%>{\hspace{-1\tabcolsep}}, height=8ex,
\begin{tabular}{>{$}c<{$}S[table-format=1.2]*{4} {S[table-format=2.2]}}
\rowcolor{Navy!60}%
 \toprule
\textbf{\diagbox[width=4cm, linecolor=PowderBlue!50,linewidth=1.2pt]{\raisebox{0ex}{\color{white}variables}}{ \raisebox{-1.5\height}{\, \color{white}$\boldsymbol\Phi$}}}
& {\color{white}\bfseries 0.1\,\%} &{\color{white}\bfseries 0.5\,\%} &{\color{white}\bfseries 1\,\%} & {\color{white}\bfseries1.5\,\%} & {\color{white}\bfseries 2\,\%} \\ \midrule
x & 3.34 & 16.19 & 31.11 & 44.65 & 56.77 \\
y & 3.23 & 15.73 & 30.38 & 43.79 & 55.91 \\
\dot{x} & 3.36 & 16.2 & 31.09 & 44.61 & 56.80 \\
\dot{y} & 3.23 & 15.73 & 30.38 & 43.77 & 55.91 \\
\bottomrule
\end{tabular}
\end{table}

\end{document} 

enter image description here

0

The environment {NiceTabular} of nicematrix has its own command \diagbox to slash cells.

\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{nicematrix}
\usepackage{caption,booktabs}
\usepackage{siunitx}
\sisetup{table-number-alignment=center}

\begin{document}

\begin{table}
\caption{Decreasing percentage in amplitude}
\label{tab:amplitude decreasing percentage}
\centering
\renewcommand{\arraystretch}{1.5}
\setlength{\tabcolsep}{15pt}
\begin{NiceTabular}{w{c}{15mm}S[table-format=1.2]*{4}{S[table-format=2.2]}}
\CodeBefore
  \rowcolors{2}{PowderBlue!50}{PowderBlue!25}
  \rowcolor{Navy!60}{1}
\Body
  \toprule
    \diagbox{\color{white}variables}{\color{white}\strut$\boldsymbol\Phi$}
      \RowStyle{\color{white}\bfseries}
      & {0.1\,\%} &  {0.5\,\%} &  {1\,\%} & {1.5\,\%} &  {2\,\%} \\ 
  \midrule
    $x$ & 3.34 & 16.19 & 31.11 & 44.65 & 56.77 \\
    $y$ & 3.23 & 15.73 & 30.38 & 43.79 & 55.91 \\
    $\dot{x}$ & 3.36 & 16.2 & 31.09 & 44.61 & 56.80 \\
    $\dot{y}$ & 3.23 & 15.73 & 30.38 & 43.77 & 55.91 \\
  \bottomrule
\end{NiceTabular}

\end{table}

\end{document}

Output of the first code

However, the rule is drawn by \diagbox in the current color of the rules (which may be set with \arrayrulecolor). If you want a white rule, you have to draw a second rule over the first one by using TikZ and the PGF/TikZ nodes created by nicematrix.

\documentclass[a4paper,12pt]{article}
\usepackage{geometry}
\usepackage[svgnames]{xcolor}
\usepackage{nicematrix,tikz}
\usepackage{caption,booktabs}
\usepackage{siunitx}
\sisetup{table-number-alignment=center}

\begin{document}

\begin{table}
\caption{Decreasing percentage in amplitude}
\label{tab:amplitude decreasing percentage}
\centering
\renewcommand{\arraystretch}{1.5}
\setlength{\tabcolsep}{15pt}
\begin{NiceTabular}{w{c}{15mm}S[table-format=1.2]*{4}{S[table-format=2.2]}}
\CodeBefore
  \rowcolors{2}{PowderBlue!50}{PowderBlue!25}
  \rowcolor{Navy!60}{1}
\Body
  \toprule
    \diagbox{\color{white}variables}{\color{white}\strut$\boldsymbol\Phi$}
      \RowStyle{\color{white}\bfseries}
      & {0.1\,\%} &  {0.5\,\%} &  {1\,\%} & {1.5\,\%} &  {2\,\%} \\ 
  \midrule
    $x$ & 3.34 & 16.19 & 31.11 & 44.65 & 56.77 \\
    $y$ & 3.23 & 15.73 & 30.38 & 43.79 & 55.91 \\
    $\dot{x}$ & 3.36 & 16.2 & 31.09 & 44.61 & 56.80 \\
    $\dot{y}$ & 3.23 & 15.73 & 30.38 & 43.77 & 55.91 \\
  \bottomrule
\CodeAfter \tikz \draw [white,thick] (1-|1) -- (2-|2) ;
\end{NiceTabular}

\end{table}

\end{document}

Output of the second code

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .