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:

  • 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 Sep 29 '16 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. – Steven B. Segletes Sep 29 '16 at 18:44
  • Remove the @{} – Yiannis Lazarides Sep 29 '16 at 19:34
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.

  • Option 2 could be better implemented with a new environment – egreg Sep 30 '16 at 6:26

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.