Graphics, Figures & TablesTable Border Formatting with Colour

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Neo63
Posts: 6
Joined: Sun Jul 31, 2011 3:03 am

Table Border Formatting with Colour

Post by Neo63 »

Hi I recently started learning LaTex. I'm making a data table and I'm having some trouble making the outer border 40% gray. I got most of the commands here off of the internet so I'm not exactly sure what I'm doing here.

Code: Select all

\renewcommand{\arraystretch}{1.3}
\begin{tabular}{!{\color[gray]{.4}\vrule width 2pt}p{6mm}| p{18mm}| p{18mm}| p{18mm}!{\color[gray]{.4}\vrule width 2pt}}
    \noalign{\color[gray]{.4}\hrule height 2pt}
   	Index &Caliper Width ($w_{CB}$) ($\pm$.01 cm)&Caliper Height ($h_{CB}$) ($\pm$.01 cm)&Caliper Length ($l_{CB}$) ($\pm$.01 cm)\\
    \hline
    1     & 2.39  & 2.46  & 5.15 \\
\hline
    2     & 2.33  & 2.48  & 5.17 \\
\hline
    3     & 2.35  & 2.45  & 5.10 \\
\hline
    4     & 2.33  & 2.48  & 5.16 \\
\hline
    5     & 2.32  & 2.47  & 5.17 \\
\hline
    6     & 2.30  & 2.49  & 5.16 \\
\hline
    7     & 2.31  & 2.40  & 5.18 \\
\hline
    8     & 2.40  & 2.47  & 5.14 \\
\hline
    9     & 2.34  & 2.48  & 5.17 \\
\hline
    10    & 2.32  & 2.49  & 5.15 \\
\hline
    Avg   & 2.34 $\pm$.03 & 2.47 $\pm$.03 & 5.16 $\pm$.02 \\
    \noalign{\color[gray]{.4}\hrule height 2pt}

    \end{tabular}
The code works but the first two vertical lines extend beyond the table for some reason. Any help is greatly appreciated.
Last edited by Neo63 on Mon Aug 01, 2011 12:24 am, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Table Border Formatting with Colour

Post by localghost »

Please always provide a complete example that is compilable as is for everybody. Otherwise specific help becomes very difficult especially when a problem is more complicated.

The quite new tabu package makes typesetting of such tables much easier. And in general I would reorganize the table a little bit.

Code: Select all

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}      % Enable Cork Encoding (Type 1 EC fonts)
\usepackage[utf8]{inputenc}   % Input encoding for special characters (if needed, optional)
\usepackage{caption}          % Customize float captions
\usepackage{mathtools}        % Loads »amsmath«
\usepackage{%
  multirow,                   % Table entries over several rows
  tabu                        % Enhance typesetting of tables
}
\usepackage{xcolor}           % Enable colors
\usepackage{siunitx}          % Format numbers and typeset physical units

\captionsetup{%
  font=small,
  labelfont=bf,
  tableposition=top
}

\sisetup{%
  load-configurations=abbreviations,
  separate-uncertainty=true
}

\begin{document}
  \begin{table}[!ht]
    \caption{Table with gray border}\label{tab:border}
    \centering
    \setlength{\extrarowsep}{2pt}
    \taburulecolor{gray}
    \begin{tabu}{|[2pt,gray] c|[black] S|[black] S|[black] S|[2pt,gray]}\tabucline[2pt]{-}
      {\multirow{2}{*}[2pt]{Index}} & {Caliper Width}  & {Caliper Height} & {Caliper Length} \\[-4pt]
      & {$w_\text{CB}$ ($\pm\SI{.01}{\cm}$)} & {$h_\text{CB}$ ($\pm\SI{.01}{\cm}$)} & {$l_\text{CB}$ ($\pm\SI{.01}{\cm}$)} \\ \taburulecolor{black} \hline
      1   & 2.39    & 2.46    & 5.15 \\ \hline
      2   & 2.33    & 2.48    & 5.17 \\ \hline
      3   & 2.35    & 2.45    & 5.1  \\ \hline
      4   & 2.33    & 2.48    & 5.16 \\ \hline
      5   & 2.32    & 2.47    & 5.17 \\ \hline
      6   & 2.3     & 2.49    & 5.16 \\ \hline
      7   & 2.31    & 2.4     & 5.18 \\ \hline
      8   & 2.40    & 2.47    & 5.14 \\ \hline
      9   & 2.34    & 2.48    & 5.17 \\ \hline
      10  & 2.32    & 2.49    & 5.15 \\ \hline
      Avg & 2.34(3) & 2.47(3) & 5.16(2) \\ \taburulecolor{gray} \tabucline[2pt]{-}
    \end{tabu}
  \end{table}
\end{document}
The typesetting of numbers in general and their alignment in tables is enhanced by the siunitx package. Have a look at the manuals of the involved packages to understand what they do (see comments in the code above).


Best regards and welcome to the board
Thorsten
Neo63
Posts: 6
Joined: Sun Jul 31, 2011 3:03 am

Re: Table Border Formatting with Colour

Post by Neo63 »

I apologize, only after I submitted my topic did I read through the guidelines for posting. I will certainly take a look at these packages. Thanks.
Post Reply