Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 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

share|improve this question
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 '11 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 '11 at 17:17
    
Mico, thanks, it did it. If you write a reply I'll check it as answer. –  AkiRoss Nov 20 '11 at 17:42
    
Thanks, I've done so! –  Mico Nov 20 '11 at 18:43

3 Answers 3

up vote 6 down vote accepted

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

share|improve this answer

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

share|improve this answer
    
Shouldn't the second instruction be \def\arraystretch{1}? –  Mico Nov 20 '11 at 22:11
    
no it shouldn't –  Herbert Nov 21 '11 at 5:32

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

share|improve this answer
    
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 '11 at 17:48

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.