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 am placing figures in a tabularx and I am having trouble getting them to embed properly. I keep getting an annoying spacer before the figure... Now if only this space could be split evenly before and after the figure I wouldn't mind, but it's always on the LEFT - no matter what I try (>\centering didn't work >\raggedright either).

Do you have any suggestions?

Here is my code and a screenshot :

\begin{table*}[t!]
%make things in tabularx columns vertically centered
\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}
\newcolumntype{y}{>{\small\centering\arraybackslash}X}
\centerline{
\begin{small}
\begin{tabularx}{7in}{>{\small\raggedright\arraybackslash}p{0.05\textwidth}|y|y|y|y|y|y|y|y|}
Symbol  &
\includegraphics[width=0.70in]{../images/paper/charlie.jpg}&
\includegraphics[width=0.70in]{../images/paper/charlie.jpg}& 
\includegraphics[width=0.70in]{../images/paper/charlie.jpg}& 
\includegraphics[width=0.70in]{../images/paper/charlie.jpg}& 
\includegraphics[width=0.70in]{../images/paper/charlie.jpg}& 
\includegraphics[width=0.70in]{../images/paper/charlie.jpg}& 
\includegraphics[width=0.70in]{../images/paper/charlie.jpg}& 
\includegraphics[width=0.70in]{../images/paper/charlie.jpg}\\ \hline
B   & & & test & is text centered &
\end{tabularx}
\end{small}}
    \caption{RAAAAAAAAAGE}
    \label{tab:rage}    
\renewcommand{\tabularxcolumn}[1]{>{\small}p{#1}}
\end{table*}

Annoying spaces from hell.

EDIT : After some more toying around, I think these spaces are margins, and it's because my table is too crowded that they were omitted on the right side... so reducing the sizes of my images fixed the whole thing. Over! However if you have anything to add go ahead, I'll be glad to hear what you have to say!

Here it is once I removed one column to make space... no more rage

share|improve this question
add comment

3 Answers

up vote 2 down vote accepted

I'm not sure what else can be said. You may be interested in controlling the tabcolsep parameter:

\documentclass[10pt]{article}
\usepackage{tabularx}
\usepackage{xcolor}

\begin{document}

\begin{tabular}{c|c|c}
\colorbox{yellow}{point}& \colorbox{yellow}{point}&\colorbox{yellow}{point} \\
\end{tabular}

\setlength\tabcolsep{0pt}
\begin{tabular}{c|c|c}
\colorbox{red}{line}& \colorbox{blue}{line}&\colorbox{green}{line} \\
\end{tabular}

\end{document}
share|improve this answer
add comment

Modifying \tabcolsep is a workable solution. However, it is not in general the best way out since it creates 'document-global' rather than 'table-local' effects. In other words, coded this way, all subseqent tabular layouts come under its sway. For this reason, you will rarely see TeX/LaTeX code written like this. The more common approach is to insert @{} in those places in your table column specifier where you want to eliminate the TeX-provided extra columnar padding.

(BTW, you can include whatever you want in between the braces of @{}, e.g., @{:} to introduce : column separators. In your case you don't want anything, hence the empty {} parameter.)

Here's some code to illustrate some somewhat more standard alternatives:

\documentclass[10pt]{article}
\usepackage{tabularx}
\usepackage{xcolor}

\begin{document}

% Problem: unwanted column separator spacing
\begin{tabular}{|c|c|c}
\colorbox{red}{box}&\colorbox{yellow}{box}&\colorbox{green}{box} \\
\end{tabular}\vspace{\baselineskip}

% Solution 1: Eliminates column spacing. However, the effect is global. Unless
%             some care is taken by inserting it in a group or by manually
%             saving and restoring the column separator spacing, it breaks
%             subsequent table layouts.
\setlength\tabcolsep{0pt}
\begin{tabular}{|c|c|c|}
\colorbox{red}{box}&\colorbox{yellow}{box}&\colorbox{green}{box} \\
\end{tabular}\vspace{\baselineskip}

% Solution 1b: fixes the problem introduced in the solution above.
\begingroup
\setlength\tabcolsep{0pt}
\begin{tabular}{|c|c|c|}
\colorbox{red}{box}&\colorbox{yellow}{box}&\colorbox{green}{box} \\
\end{tabular}\vspace{\baselineskip}
\endgroup

% Solution 2: `TeX-standard' solution - include `@{}' at places where extra
%             columnar padding is unwanted.
\begin{tabular}{|@{}c@{}|@{}c@{}|@{}c@{}|}
\colorbox{red}{box}&\colorbox{yellow}{box}&\colorbox{green}{box} \\
\end{tabular}\vspace{\baselineskip}

% Solution 2b: Best solution - write `*{n}{column pattern}' to repeat the pattern
%              n times (saves a little typing, maybe easier to maintain).
\begin{tabular}{*{3}{|@{}c@{}}|}
\colorbox{red}{box}&\colorbox{yellow}{box}&\colorbox{green}{box} \\
\end{tabular}

\end{document}
share|improve this answer
add comment

You do have a space before your pictures, just after the & (a newline, to be more precise). I'm pretty sure just commenting it would do the job :

\includegraphics[width=0.70in]{../images/paper/charlie.jpg}&%
share|improve this answer
    
This was meant as a comment. –  Michaël Sep 22 '10 at 1:00
add comment

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.