GeneralReduce Width of Table Column

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
john84141
Posts: 4
Joined: Fri May 11, 2012 10:10 am

Reduce Width of Table Column

Post by john84141 »

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:

Code: Select all

\begin{small}
        \begin{tabular}{|@{}c@{}|}
            A\\B\\C\\   
        \end{tabular}
\end{small}
Compare with (in the following code, there is unwanted extra space) :

Code: Select all

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Reduce Width of Table Column

Post by localghost »

Just for information to other users for awareness of possibly already existing solutions. The question has also been posted to {TeX} SX.

There is already an answer that you accepted explicitly. Do you want others here to solve a problem that has already a solution? Not very polite.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Reduce Width of Table Column

Post by Stefan Kottwitz »

As Gonzalo wrote in the answer linked by Thorsten: simply use \small instead of \begin{small}.

So your code could be, without producing the undesired space:

Code: Select all

\begin{tabular}{|@{}c@{}|}
  \small
  \begin{tabular}{@{}c@{}}
    A\\B\\C\\  
  \end{tabular}
\end{tabular}
The effect of \small is already limited by the environment where it's in. Generally, I would not use such a command in an environment syntax - similarly one could even write

Code: Select all

\begin{tableofcontents}
\end{tableofcontents}
which works - but it's not planned to be done this way.

If I want to limit the effect, and if it's not already implicitly done by an outer environment, such as here, I would use grouping, i.e. write

Code: Select all

{\small .... }
or even

Code: Select all

\begingroup
\small .... 
\endgroup
to make it clear. And i would consider to end the paragraph (or line) before I end the scope, i.e. the group, to let the paragraph algorithm choose the line spacing which matches \small, instead of the font size later.

Stefan
LaTeX.org admin
john84141
Posts: 4
Joined: Fri May 11, 2012 10:10 am

Re: Reduce Width of Table Column

Post by john84141 »

Thanks
Post Reply