Question

I am facing problem in autogeneration of list of tables in my latex code.Actually I am new in latex I tried adding \listoftables also some packages such as fancyhdr still I couldn't make it.Below I m giving a sample code please suggest me the changes.

\documentclass{article}

\usepackage{amssymb}
\usepackage{amsmath}
 \usepackage{graphicx}
 \usepackage{fancyhdr}

\begin{document}

 \listoftables
\noindent Test Cases

\noindent Test Case 1

\begin{enumerate}
\item  ID1: Taking input query from user and store raw data

\item  DESCRIPTION: Allow user to provide input from available list of keywords and 
store collected raw data in database.
\end{enumerate}

\begin{tabular}{|p{0.8in}|p{0.9in}|p{0.9in}|p{0.9in}|p{0.9in}|} \hline 
Steps & Input & Expected output & Actual Result & Remarks \\ \hline 
Select the keyword as required & Keyword is given as input for further processing &   
Background process for collecting tweets related to keyword must start & Background  
process for collecting tweets related to keyword is started & Pass \\ \hline 
Store raw tweet data in temporary storage & Raw tweet data collected by background 
process & The raw tweet data must be stored in database & The raw tweet data is stored 
in database & Pass \\ \hline 
\end{tabular}

\textbf{Table 1: Test Case 1}

\noindent \textbf{}

\noindent Test Case 2

\begin{enumerate}
\item  ID2: Processing and displaying collected data

\item  DESCRIPTION: The raw tweets need to be separated, categorized and processed  
tweets are displayed.
\end{enumerate}

\begin{tabular}{|p{0.8in}|p{0.9in}|p{0.9in}|p{0.9in}|p{0.9in}|} \hline 
Steps & Input & Expected output & Actual result & Remarks \\ \hline 
Run background process for sorting tweets & Raw tweets are provided for sorting & 
Tweets must be processed for separating their properties and stored in other tables as  
per attributes & Tweets are processed as per their properties and stored in other 
tables as per attributes  & Pass \\ \hline 
Retrieve tweets from database and show them on user interface & Query for retrieving  
tweets from database  & The tweets must be displayed on user interface with name and 
profile picture of tweeter user who tweeted. & The tweets are displayed on the user 
interface with all expected properties & Pass \\ \hline 
\end{tabular}

\textbf{Table 2: Test Case 2}

\end{document}
Was it helpful?

Solution

A tabular alone is just a box in LaTeX and can be used anywhere; it does not represent what is considered a table, which is the first thing you "need" in order to place something in the List of Tables (LoT) . Well, technically you don't need a table, but I'll get to that in a moment. In your example you might use

\listoftables

...

\begin{table}[ht]
  \begin{tabular}{..}
    ...
  \end{tabular}
  \caption[This is a table]{This is a table that holds valuable information.}
\end{table}

...

It's part of the \caption's content that makes its way into the LoT. More specifically, it's the (optional) first argument, or if that's not specified, the (mandatory) second argument that is printed in the LoT.

Note that we've wrapped the tabular inside a table. The latter is called a float, which can more around in the document. If you want to manage the placement of this float (perhaps because you don't like the way LaTeX decides this), read up on How to influence the position of float environments like figure and table in LaTeX?

One way of forcing the placement is to avoid a table (float) completely, and use the caption package's \captionof{table} functionality. This tricks LaTeX into thinking that it's inside a table (float), and allows you to set a "regular \caption". The tiny capt-of package provides similar functionality*. To be clear, you could use

...

\begin{tabular}{..}
  ...
\end{tabular}\par\nobreak
\captionof{table}[This is a table]{This is a table that holds valuable information.}

...

The use of \par\nobreak attempts to keep the tabular and it's associated \caption together on the same page.

Of course, the above discussion holds just as well for figures. That is, you can have (say) \includegraphics[..]{...} anywhere in the document, but you need to use an appropriate \caption for that figure (or \captionof) for it to make it into the List of Figures (LoF).

* Both caption and capt-of suffer from the fact that it fools LaTeX permanently: It updates \@captype but never resets it. As such, it's perhaps better to provide some scope within which you use \captionof, like \begingroup...\endgroup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top