1

I use the tabu package to typeset my table, mainly with X type column. My overall goal is to have the same inner padding between the table border and the text and between the text cells.

By default, LaTeX puts a \tabcolsep between every cell border (left or right) and the text. This means that between to texts, there will be two \tabcolsep but between the text and the border of the table there will be only one:

|__text__|__text__|
 1x      2x      1x

As I don't use vertical rule, I would like to have one \tabcolsep everywhere.

|__text__text__|

MWE:

\documentclass[a4paper, 11pt]{article}
\usepackage{tabu}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

\definecolor{tableHeader}{RGB}{127, 12, 0}
\definecolor{tableLineOne}{RGB}{245, 245, 245}
\definecolor{tableLineTwo}{RGB}{224, 224, 224}

\begin{document}

    \taburowcolors[2] 2{tableLineOne .. tableLineTwo}
    \everyrow{\tabucline[.4mm  white]{}}
    \tabulinesep = ^4mm_3mm

    \begin{tabu}{X X X}
        \rowfont{\color{white}\bfseries\sffamily}\rowcolor{tableHeader}
        Matiere & Note & Prof\\
        Francais & 5 & Melis\\
        Math & 5.5 & De Kempeneer\\
        Allemand & 4.5 & Bickel\\
    \end{tabu}

\end{document}

(Compiled with XeLaTeX)

Can anyone give me some help?

3

It seems a slightly odd request but you can make all the spaces 2\tabcolsep by

\documentclass[a4paper, 11pt]{article}
\usepackage{tabu}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}

\definecolor{tableHeader}{RGB}{127, 12, 0}
\definecolor{tableLineOne}{RGB}{245, 245, 245}
\definecolor{tableLineTwo}{RGB}{224, 224, 224}

\begin{document}

    \taburowcolors[2] 2{tableLineOne .. tableLineTwo}
    \everyrow{\tabucline[.4mm  white]{}}
    \tabulinesep = ^4mm_3mm

    \begin{tabu}{@{\hspace{2\tabcolsep}}lll@{\hspace{2\tabcolsep}}}
        \rowfont{\color{white}\bfseries\sffamily}\rowcolor{tableHeader}
        Matiere & Note & Prof\\
        Francais & 5 & Melis\\
        Math & 5.5 & De Kempeneer\\
        Allemand & 4.5 & Bickel\\
    \end{tabu}

\end{document}
  • Thanks for your quick answer! However it does not solve my problem. I want to add space inside my colored lines. The @{} insert it before and after... – HarveyShepp Sep 4 '15 at 14:02
  • ah OK, You could instead do >{\kern\tabcolsep}l for the first column I suppose, and similar with < for the last. – David Carlisle Sep 4 '15 at 14:21
  • Thank you, it worked like a charm for l column type! Does such an solution exists for X columns (from the tabu package)? – HarveyShepp Sep 4 '15 at 17:51
  • @Thib1235 no (not so easily), but you could put an empty l column at the front (but would need extra & on each row – David Carlisle Sep 5 '15 at 10:01
  • Perfect! I was wondering however if there isn't a less hacky solution. But for now, it will perfectly do the job! – HarveyShepp Sep 5 '15 at 11:35

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.