1

I have a table with multiple columns one of which is "Serial Number". Clearly, this is the column of smallest width, but by default, Latex is assigning comparatively more width to this column. As a result, the table is going beyond the width of the page column.

How can I adjust the width of only this column (keeping other column width unchanged)?

I am uploading the code and the table image.

 \begin{table}[h]
\centering
 \begin{tabular}{|c |c |c |} 
 \hline
 \textbf{Serial Number} & \textbf{Key} & \textbf{Value} \\[0.5ex] 
 \hline \hline
 (1) & State/Province & Uttar Pradesh  \\ 
 \hline
 (2) & Number of districts & 75 \\
 \hline
 (3) & Number of speakers & 1500 \\ 
 \hline
 (4) & Data content & names of crops, fruits markets \& districts; yes/no \\
 \hline
 (5)  & Duration of an utterance & 3-5 seconds \\ 
\hline
 (6) & Background enviroment & silent, noisy, extremely noisy \\
 \hline
 (7) & Speaker composition & male \& female (age group: 18-76 years) \\
 \hline
 (8) & Speaker-gender ratio & M:F = 4:1 \\
 \hline
 (9) & Other variations & different mobile brands, mobile/landline \\
 \hline 
 \end{tabular}
 \caption{Statistics of Data Collection Phase}
\label{table:1}
\end{table}

This is the image

image showing table going out of page boundaries

The problem persists

the table boundaries cross the limits

  • Rather than posting code snippets you are more likely to get help if you post a compilable minimal working example because this makes it much easier for people to test and troubleshoot your code. Looking at what you have posted it does not look like you need any special packages but I don't know what the [![\...][1]][1] is there for. You should explain if this is important in your real application. You might also want to look at the tabularx package. – Andrew Sep 22 '16 at 6:39
  • the column is set to exactly the width of its widest content (which is Serial Number) to make it narrower, just make that narrower, eg two lines \begin{tabular}{@{}c@{}}Serial\\Number\end{tabular} – David Carlisle Sep 22 '16 at 6:46
  • 1
    unrelated but I wouldn't centre those columns, makes it very hard to read the table – David Carlisle Sep 22 '16 at 6:48
  • #Andrew I am uploading the minimal code in the folder. The file is named main.tex – Upendra Pratap Singh Sep 22 '16 at 7:54
2

Even if you split the header string "Serial Number" across two lines (which you should do, by the way), the table will likely still be too wide to fit inside the textblock unless line breaks are allowed in columns 2 and/or 3. For the table at hand, allowing line breaks in column 2 doesn't seem like a good idea. However, line breaks would appear to be OK in column 3. I therefore suggest you use a tabularx environment and a (modified) X column type for column 3 to allow line breaks to happen as needed.

I further recommend you give the table a more open look by getting rid of all vertical lines and most horizontal lines and by not using boldface for the header text.

enter image description here

\documentclass{article}
\usepackage{tabularx,booktabs}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\newlength\mylen
\settowidth\mylen{Number} % store width of string "Number"
\begin{document}

\begin{table}
\begin{tabularx}{\textwidth}{@{} p{\mylen} l L @{}} 
 \toprule
 Serial Number & Key & Value \\
 \midrule
 (1) & State/Province & Uttar Pradesh  \\ 
 (2) & Number of districts & 75 \\ 
 (3) & Number of speakers & 1500 \\ 
 (4) & Data content & names of crops, fruits markets and districts; yes/no \\
 (5) & Duration of an utterance & 3--5 seconds \\ 
 (6) & Background environment & silent, noisy, extremely noisy \\ 
 (7) & Speaker composition & male \& female (age group: 18--76 years) \\
 (8) & Speaker-gender ratio & M:F = 4:1 \\ 
 (9) & Other variations & different mobile brands, mobile/landline \\
 \bottomrule 
\end{tabularx}
\caption{Statistics of Data Collection Phase}
\label{table:stats}
\end{table}

\end{document}

Addendum: The OP has revealed in a comment that his/her document uses a two-column layout. In such cases, one can either uses a full-width table* environment (and place the tabular material centered in the table* environment) or allow line breaks in both columns 2 and 3. Both possibilities are illustrated in the following example.

enter image description here

\documentclass{IEEEconf} % example of a two-column document class
\usepackage{tabularx,booktabs,ragged2e,lipsum}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}
\newlength\mylen
\settowidth\mylen{Number} % find and store width of "Number" string
\begin{document}
\lipsum[1] % filler text

\begin{table*} % full-width environment
\centering
\begin{tabular}{@{} p{\mylen} ll @{}} % use two "l" columns, no line breaks needed
 \toprule
 Serial Number & Key & Value \\
 \midrule
 (1) & State/Province & Uttar Pradesh  \\ 
 (2) & Number of districts & 75 \\ 
 (3) & Number of speakers & 1500 \\ 
 (4) & Data content & names of crops, fruits markets \& districts; yes/no \\
 (5) & Duration of an utterance & 3--5 seconds \\ 
 (6) & Background environment & silent, noisy, extremely noisy \\ 
 (7) & Speaker composition & male \& female (age group: 18--76 years) \\
 (8) & Speaker-gender ratio & M:F = 4:1 \\ 
 (9) & Other variations & different mobile brands, mobile\slash landline \\
 \bottomrule 
\end{tabular}
\caption{Statistics of Data Collection Phase}
\label{table:stats-wide}
\end{table*}

\lipsum[2-9] % more filler text

\begin{table} % column-width environment
\setlength\tabcolsep{3pt} % default value: 6pt
\begin{tabularx}{\columnwidth}{@{} p{\mylen} LL @{}} % use *two* "L" columns
 \toprule
 Serial Number & Key & Value \\
 \midrule
 (1) & State/Province & Uttar Pradesh  \\ 
 (2) & Number of districts & 75 \\ 
 (3) & Number of speakers & 1500 \\ 
 (4) & Data content & names of crops, fruits markets \& districts; yes/no \\
 (5) & Duration of an utterance & 3--5 seconds \\ 
 (6) & Background environment & silent, noisy, extremely noisy \\ 
 (7) & Speaker composition & male \& female (age group: 18--76 years) \\
 (8) & Speaker-gender ratio & M:F = 4:1 \\ 
 (9) & Other variations & different mobile brands, mobile\slash land\-line \\
 \bottomrule 
\end{tabularx}
\caption{Statistics of Data Collection Phase}
\label{table:stats-narrow}
\end{table}

\lipsum[9-12] % still more filler text

\end{document}
  • still the horizontal lines are going beyond the page column width...see the snapshot – Upendra Pratap Singh Sep 22 '16 at 10:28
  • 1
    @Snowbell How was Mico supposed to know that this was a two-column document? You didn't say this anywhere. Is using table* instead of table an option? Then the table spans both columns. – Torbjørn T. Sep 22 '16 at 10:35
  • @Snowbell -- I will admit freely and unabashedly that I'm absolutely no good at divination. If an important piece of information isn't stated explicitly, there's virtually no chance that I will guess it on my own. Are you allowed to reveal which document class and main font size are in use in your document, or are these items closely-guarded secrets? – Mico Sep 22 '16 at 10:51
  • @Snowbell - I've provided an addendum to provide two additional solutions that are appropriate for a two-column document. – Mico Sep 22 '16 at 13:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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