GeneralAdjusting width of table

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
ma501th
Posts: 50
Joined: Tue Apr 08, 2008 7:31 pm

Adjusting width of table

Post by ma501th »

My tables seems to have different width to one another. How do i set the width of the colums in a table.

This is the coding for the table i am using:

\begin{table}[H]
\begin{center}
\begin{tabular}{ | l | l | }
\hline
Test No & 1 \\ \hline
Description & Selecting continue from welcome page \\ \hline
Input & Button click \\ \hline
Result & Expected result \\ \hline
Conclusion & The button did its function and routed the user to the next page \\
\hline
\end{tabular}
\caption{Test case 1: Welcome page button}
\label{tb:Test case 1: Welcome page button}
\end{center}
\end{table}

Where would i need to apply the neccessary coding:

Recommended reading 2024:

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

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

User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Adjusting width of table

Post by gmedina »

You can use the p{...} (or m{...} if the array package was loaded) modifier in the declaration of the table format, as the following example suggests:

Code: Select all

\documentclass{article}
\usepackage{array}

\begin{document}

\begin{table}[H]
  \setlength\extrarowheight{3pt}
  \centering
  \begin{tabular}{|p{2cm}|p{5cm}|}
    \hline
    Test No & 1 \\ \hline
    Description & Selecting continue from welcome page \\ \hline
    Input & Button click \\ \hline
    Result & Expected result \\ \hline
    Conclusion & The button did its function and routed the user to the next page \\
    \hline
  \end{tabular}
  \caption{Test case 1: Welcome page button}
  \label{tb:Test_case_1}
\end{table}

%requires the array package
\begin{table}[H]
  \setlength\extrarowheight{3pt}
  \centering
  \begin{tabular}{|m{2cm}|m{5cm}|}
    \hline
    Test No & 1 \\ \hline
    Description & Selecting continue from welcome page \\ \hline
    Input & Button click \\ \hline
    Result & Expected result \\ \hline
    Conclusion & The button did its function and routed the user to the next page \\
    \hline
  \end{tabular}
  \caption{Test case 2: Welcome page button}
  \label{tb:Test_case_2}
\end{table}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
ma501th
Posts: 50
Joined: Tue Apr 08, 2008 7:31 pm

Re: Adjusting width of table

Post by ma501th »

Could you please tell the difference between the following two line of codes

\caption{xyz}
\label{tb:xyz}
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Adjusting width of table

Post by gmedina »

The \caption command sets the caption for your float enviroment (usually table or figure); the \label{key} command allows you to cross-reference objects using the corresponding \ref{key} command. Inside a floating environment you should always use \label after \caption.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Adjusting width of table

Post by localghost »

ma501th wrote:Could you please tell the difference between the following two line of codes

\caption{xyz}
\label{tb:xyz}
Basic LaTeX documentation is available with lshort and l2tabu. Useful hints about float environments can be found in epslatex.


Best regards
Thorsten¹
Post Reply