Graphics, Figures & TablesSpacing of color borders using varwidth and tabular

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Spacing of color borders using varwidth and tabular

Post by cbkschroeder »

Hi,

Thanks for reading my posting.

In the MWE provided, I'd like to increase the "gray border" around the two-line table entries. The single-line entries have perfect spacing, but the two line entries, well, not so much. The characters are right against the gray border.

Code: Select all

\documentclass[12pt]{article}

\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{varwidth}
\usepackage[smaller,printonlyused,withpage]{acronym}
\usepackage{xfrac} 
\usepackage[load-configurations=binary]{siunitx}

\newcommand{\vw}[2]{\begin{varwidth}{#1}\centering #2\end{varwidth}}

\begin{document}

\begin{table}
\newcommand{\columnwidtha}{2in}
\rowcolors{2}{gray!30}{}
\centering
\begin{tabular}{c} \toprule
    {Material} \\ \midrule \addlinespace
    \vw{\columnwidtha}{Aluminum}                         \\ \addlinespace
    \vw{\columnwidtha}{\SI{63}{\percent}/\SI{37}{\percent} Sn/Pb (Solder)} \\ \addlinespace
    \vw{\columnwidtha}{Silicone}                                  \\ \addlinespace
    \vw{\columnwidtha}{\ac{POM} (Delrin)}                         \\ \addlinespace
    \vw{\columnwidtha}{Polyimde (Vespel)}                        \\ \addlinespace
    \vw{\columnwidtha}{Water}                                     \\ \addlinespace
    \vw{\columnwidtha}{Copper}                                    \\ \addlinespace
    \vw{\columnwidtha}{\ac{PTFE} (Teflon)}                        \\ \addlinespace
    \vw{\columnwidtha}{Borosilicate Glass (Pyrex-7070)}  \\ \addlinespace
    \vw{\columnwidtha}{\ac{PCTFE} (Kel-F)}               \\ \addlinespace \bottomrule
\end{tabular}
\end{table}%

\begin{acronym}
\acro{PCTFE}{Polychlorotrifluoroethelyne}
\acro{POM}{Polyoxymethelyne}
\acro{PTFE}{Polytetrafluoroethylene}
\end{acronym}

\end{document}
My hunch is that this problem has everything to do with the amount of padding that the varwidth environment is giving me. I've chosen to use varwidth --- versus simply, for instance, p{2in} --- so that I can control the line breaking if need be, and still have as thin a table as possible.

If anyone could suggest a solution to the above, I'd be appreciative.

The output of the above is included as an attachment in this posting for reference.

Thanks.
Attachments
test.pdf
(36.12 KiB) Downloaded 282 times
Last edited by cbkschroeder on Mon Aug 02, 2010 9:02 pm, 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.

cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Re: Spacing of color borders using varwidth and tabular

Post by cbkschroeder »

The answer to this situation is the cellspace package. It allows one to buffer the upper and lower bounds of the row. Note that if one uses this in conjunction with siunitx, then as stated in that package's documentation, one needs to use "C" rather than "S" in the column-type definition of the tabular environment.

I'll add also that in my example above, I've used varwidth in one particular way; varwidth also provides a "V{}" column type which may be helpful.

Hopefully this serves as useful to someone in the future.

Cheers.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: Spacing of color borders using varwidth and tabular

Post by localghost »

A full code example of your solution would be nice. This would much more useful than only descriptions. At the moment I can't figure by myself how you did it.


Best regards
Thorsten
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Spacing of color borders using varwidth and tabular

Post by cbkschroeder »

Absolutely, though the solution is about as minor a change as one could make. The new code is:

Code: Select all

\documentclass[12pt]{article}

\usepackage{booktabs}
\usepackage[table]{xcolor}
\usepackage{varwidth}
\usepackage[smaller,printonlyused,withpage]{acronym}
\usepackage{xfrac} 
\usepackage[load-configurations=binary]{siunitx}
\usepackage{cellspace}

\newcommand{\vw}[2]{\begin{varwidth}{#1}\centering #2\end{varwidth}}

\begin{document}

\begin{table}
\newcommand{\columnwidtha}{2in}
\rowcolors{2}{gray!30}{}
\centering
\begin{tabular}{Cc} \toprule
    {Material} \\ \midrule \addlinespace
    \vw{\columnwidtha}{Aluminum}                         \\ \addlinespace
    \vw{\columnwidtha}{\SI{63}{\percent}/\SI{37}{\percent} Sn/Pb (Solder)} \\ \addlinespace
    \vw{\columnwidtha}{Silicone}                                  \\ \addlinespace
    \vw{\columnwidtha}{\ac{POM} (Delrin)}                         \\ \addlinespace
    \vw{\columnwidtha}{Polyimde (Vespel)}                        \\ \addlinespace
    \vw{\columnwidtha}{Water}                                     \\ \addlinespace
    \vw{\columnwidtha}{Copper}                                    \\ \addlinespace
    \vw{\columnwidtha}{\ac{PTFE} (Teflon)}                        \\ \addlinespace
    \vw{\columnwidtha}{Borosilicate Glass (Pyrex-7070)}  \\ \addlinespace
    \vw{\columnwidtha}{\ac{PCTFE} (Kel-F)}               \\ \addlinespace \bottomrule
\end{tabular}
\end{table}%

\begin{acronym}
\acro{PCTFE}{Polychlorotrifluoroethelyne}
\acro{POM}{Polyoxymethelyne}
\acro{PTFE}{Polytetrafluoroethylene}
\end{acronym}

\end{document}
This differs from the old code in that, in the preamble, I added:

Code: Select all

\usepackage{cellspace}
Furthermore, the line:

Code: Select all

\begin{tabular}{c} \toprule
was changed to:

Code: Select all

\begin{tabular}{Cc} \toprule
which, if I wasn't using siunitx, I think would have looked like:

Code: Select all

\begin{tabular}{Sc} \toprule
instead --- correct me if I'm wrong.

Attached is the new output for consideration. The buffering is alterable as described in the cellspace package documentation, though the above was satisfactory to me.

Hope this is clearer!

Cheers.
Attachments
test.pdf
(36.12 KiB) Downloaded 272 times
Post Reply