8

I'm creating in LyX a table wich has a single character for every cell. Problem is, a lot of space is wasted, because each cell has some padding points which I'd like to reduce. A cell is now big enough to contain 3 characters, but I need them to be a little bigger than the character itself. Ideal objective is to get all the cells square shaped of equal size.

A screenshot is attached to let you understand what I'd like to accomplish (they are not really regular as my drawing skills are poor :P)

I tried with this thread Column and row padding in tables but without luck: cells are still wide.

What can I do?

Thanks in advance ~Aki

A table with reduced padding and square cells

3
  • 5
    Have you tried reducing the value of \tablecolsep, which equals (half) the width of the whitespace between columns? Its default value is 6pt. Try \setlength\tabcolsep{3pt} for starters. Separately, you may also want to consider eliminating the vertical rules between columns entirely; when you have a lot of columns, these rules tend to take up a lot of space while not adding appreciably to the table's readability.
    – Mico
    Nov 20, 2011 at 17:09
  • Please add a minimal working example (MWE) that shows your current code, and perhaps the adjustments you've made after reading Column padding in tables.
    – Werner
    Nov 20, 2011 at 17:17
  • Mico, thanks, it did it. If you write a reply I'll check it as answer.
    – AkiRoss
    Nov 20, 2011 at 17:42

3 Answers 3

11

You may want to change the value of \tabcolsep, a length variable that equals (half) the width of the whitespace that separates columns. You use the command \setlength to change the value of this length variable. The default value of this variable is 6pt (if the main text's font size is 10pt); a value of 3pt will give you a rather tightly-set group of columns.

Separately, you may also want to consider eliminating the vertical rules between columns entirely. When one has a lot of columns, the vertical rules tend to take up a lot of space while not adding appreciably to the table's readability.

The following code and the associated image illustrate the effects that reducing the value of \tabcolsep from 6pt to 4, 3, and 2pt has. In all cases, I've eliminated all vertical rules.

\documentclass{article}
\usepackage{booktabs} % for well-spaced horizontal rules
\newcommand{\quicktabular}{%  this construct will be used several times
\begin{tabular}{*{10}{c}}
\toprule
A & B & C & D & E & F & G & H & I & J \\
A & B & C & D & E & F & G & H & I & J \\
\bottomrule
\end{tabular}}
\begin{document}
\begin{itemize}
\item Default value of \texttt{\textbackslash tabcolsep} (6pt)

 \quicktabular

\item \texttt{\textbackslash tabcolsep} = 4pt
 \setlength\tabcolsep{4pt}

 \quicktabular

\item \texttt{\textbackslash tabcolsep} = 3pt
 \setlength\tabcolsep{3pt}

 \quicktabular

\item \texttt{\textbackslash tabcolsep} = 2pt
 \setlength\tabcolsep{2pt}

 \quicktabular

\end{itemize}
\end{document}

enter image description here

11

Insert before the table with Ctrl-L for "Evil Red Text" and write \begingroup\tabcolsep=0pt\def\arraystretch{0}. After the table do the same, hit CTRL-L and write \endgroup. Then you do not have any space left and right of your entry

3
  • Shouldn't the second instruction be \def\arraystretch{1}?
    – Mico
    Nov 20, 2011 at 22:11
  • no it shouldn't
    – user2478
    Nov 21, 2011 at 5:32
  • +1 for actually answer the question (of how to solve this problem in LyX). Apr 20, 2020 at 4:39
3

I don't know how to place code in LyX, but the following should do what you want.

\documentclass{article}

\usepackage{array}
\newlength{\mystrutht}
\newcommand{\mystrut}{\rule{0pt}{\mystrutht}\rule[-1pt]{0pt}{1pt}}
\newcolumntype{C}{>{\hbox to 1em\bgroup\mystrut\hfil}c<{\hfil\egroup}}
\newenvironment{zerotabular}
  {\settoheight{\mystrutht}{A}\addtolength{\mystrutht}{1pt}%
   \setlength{\tabcolsep}{0pt}%
   \renewcommand{\arraystretch}{0}%
   \begin{tabular}}
  {\end{tabular}}

\begin{document}
\begin{zerotabular}{|C|C|C|C|}
\hline
A&A&C&G\\
\hline
C&A&A&C\\
\hline
A&C&A&A\\
\hline
\end{zerotabular}
\end{document}

The first part (between the \documentclass and \begin{document} lines) should go in the preamble code.

Each cell is typeset in a box as wide as to accommodate a capital M; interline spacing is suppressed and substituted by a hand made strut that's 1pt higher and deeper than a capital letter.

enter image description here

1
  • Thanks, but actually using a new environment discard the table-composing GUI features available for lyx (at least I think). Using \renewcommand with \tabcolsep don't require to change the LyX code, so I'll go with it as a "preferred" (i.e. more adapt with the UI) solution. Thanks anyway for this interesting example, which I'll study for my interest outside the LyX scope :)
    – AkiRoss
    Nov 20, 2011 at 17:48

You must log in to answer this question.

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