# latex tabular issue

I am creating a tabular in LaTeX.

I want one column to be as small as possible, with no inter column spacing, so that it's just enough to fit the text. I know the answer to this question: I need to use @{}c@{}.

I also want to be able to have a linebreak wherever I want in my cell. I also know the answer to this question: I need to use a tabular within my tabular.

The problem is that I can't manage to make these two solutions work together: when I try to have 2 lines within a cell, the column gets expanded beyond the size of the text.

Here is such an example:

\begin{small}
\begin{tabular}{|@{}c@{}|}
A\\B\\C\\
\end{tabular}
\end{small}


Compare with (in the following code, there is unwanted extra space) :

\begin{tabular}{|@{}c@{}|}
\begin{small}
\begin{tabular}{@{}c@{}}
A\\B\\C\\
\end{tabular}
\end{small}
\end{tabular}

-
Welcome to TeX.SE. Note that small is a macro: \small not an environment (however, it also works without error). You might simply have some unwanted spaces, try putting % after the } at the end of the source lines. – Martin Scharrer May 29 '12 at 14:53
There are two extra spaces: one after \begin{small} and the second after \end{tabular}. Saying only \small (and removing \end{small}) will solve the issue, as Gonzalo says. – egreg May 29 '12 at 15:01
You guys are all right, thank you very much. I don't understand though why adding '%' at the line of the lines solve the issue, I don't see where there are the 'two extra spaces' you mention ? – bob May 29 '12 at 15:04
@bob a line break is taken as a blank space. Anyway, it's better not to use the font switches as environments. – Gonzalo Medina May 29 '12 at 15:05
Oh okay. I'd like to thank you all and +1 but it says 'please login or register to vote for this post'. I am logged in though, otherwise I wouldn't be able to post here... – bob May 29 '12 at 15:06

In your code, there are two spurious blank spaces: one, after \begin{small}, and the second one, after the inner \end{tabular}; you can remove those spaces using % at the end of the line. Compare the result obtained in the following example showing your code and a version with the spaces removed:

\documentclass{article}

\begin{document}

\noindent Undesired blank spaces:
\begin{tabular}{|@{}c@{}|}
\begin{small}
\begin{tabular}{@{}c@{}}
A\\B\\C\\
\end{tabular}
\end{small}
\end{tabular}

\noindent Spurious spaces removed:
\begin{tabular}{|@{}c@{}|}
\begin{small}%
\begin{tabular}{@{}c@{}}
A\\B\\C\\
\end{tabular}%
\end{small}
\end{tabular}

\end{document}


\small is a switch not an environment; use this:

\begin{tabular}{|@{}c@{}|}
\small
\begin{tabular}{@{}c@{}}
A\\B\\C\\
\end{tabular}
\end{tabular}


With this input, spurious spaces don't show up because tabular ignores white space at the start and end of cells (and the endline after \small is ignored because it's a command name).

When nesting tabulars normally is convenient to enclose the inner one using braces; in this case, however it's not necessary since the inner tabular only has one column.

-

The following works for me:

\documentclass{article}
\begin{document}
\begin{tabular}{cl}
\small
\begin{tabular}{|@{}c@{}|}
A\\B\\C
\end{tabular}&
Some more text
\end{tabular}
\end{document}


Note that the vertical rules is placed in the innermost tabular where you use your line breaks. You could also consider the makecell package which does something similar. Here's a short example that produces similar output:

\documentclass{article}
\usepackage{makecell}% http://ctan.org/pkg/makecell
\begin{document}
\begin{tabular}{|@{}c@{}|l}
\small
\makecell{A\\B\\C}&
Some more text
\end{tabular}
\end{document}

-