2

I tried to insert on a document a table (tabular) but the rendering of the code is a table without padding. Where is the error?

code:

\documentclass[11pt,a4paper,sans]{moderncv}
\moderncvstyle{casual}

\moderncvcolor{blue} 
\usepackage[utf8]{inputenc}
\usepackage[scale=0.77]{geometry}
\usepackage{multicol}
\usepackage{fancyhdr}
\usepackage{lastpage}

\usepackage{booktabs}
\usepackage{tabularx}

\usepackage{graphicx}

\pagestyle{fancy}
\fancyhf{}

...

\cvitemwithcomment{}{
\begin{tabular}{@{}llll@{}}
\toprule
XXXXXXXXXX & MMMMMM       & XXXXXXXXXXX & MMMMMMMM \\ \midrule
Lorem      & Ipsum       & dolor       & sit      \\
amet,      & consectetur & adipiscing  & elit.    \\
Aenean     & a           & lacus       & sit      \\ \bottomrule
\end{tabular}
}
{}

the result is:

3
  • Welcome to TeX.SE. Please tell us which document class you use and how the \cvitemwithcomment{} macro is defined. Please also tell us which commands you execute -- or which font-related package(s) you load -- to switch to a sans-serif font. And, do tell us if the length parameter \tabcolsep is reset (to zero length...) anywhere in your document.
    – Mico
    Commented Sep 29, 2016 at 18:41
  • 2
    It is possible the length \tabcolsep was somewhere reset to 0pt. You can try \tabcolsep=1ex\relax just prior to \begin{tabular} to see if it has an effect. Commented Sep 29, 2016 at 18:44
  • Remove the @{}
    – yannisl
    Commented Sep 29, 2016 at 19:34

1 Answer 1

2

Since you're using \cvitemwithcomment, I'm assuming you're using the moderncv document class.

The length responsible for the gap between columns in a tabular is \tabcolsep. This is defined in latex.ltx - the LaTeX kernel - but is specifically set within the document class that you use. For example, article uses

\setlength\tabcolsep{6\p@}

However, moderncv has the following comments inside moderncv.cls:

% not set on purpose
%\setlength\arraycolsep{5\p@}
%\setlength\tabcolsep{6\p@}
%\setlength\tabbingsep{\labelsep}

So, it purposely does not set any changes to \tabcolsep (and others), keeping them at their default length which is 0pt when it is defined.

If you wish to have some padding, you have the following options:

  1. Add

    \setlength{\tabcolsep}{6pt}
    

    anywhere in your preamble. Note that this may affect other components constructed by the document class wherever it uses a tabular.

  2. Use

    \begingroup
    \setlength{\tabcolsep}{6pt}
    % <your tabular content>
    \endgroup
    

    to localise the scope of the \tabcolsep changes to the specific tabular where you want to use it.

Option 2 would be advisable, since the class uses tabulars quite regularly.

1
  • Option 2 could be better implemented with a new environment
    – egreg
    Commented Sep 30, 2016 at 6:26

You must log in to answer this question.

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