0

My latex document is given below.

\documentclass[12pt]{report}
\linespread{}
\usepackage{fancyhdr}
\usepackage{amsmath,amssymb}
\usepackage{caption}
\usepackage{relsize}
\usepackage[font={small,it}]{caption}
\usepackage{listings}
\usepackage{color} 
\definecolor{mygreen}{RGB}{28,172,0} 
\definecolor{mylilas}{RGB}{170,55,241}
\usepackage[titletoc,toc]{appendix}
\usepackage{graphicx}
\usepackage{setspace}  
\usepackage{changepage}
\usepackage[textwidth=16cm,textheight=24cm,margin=2cm]{geometry}
\usepackage[colorlinks,citecolor=red]{hyper ref}
\hypersetup{colorlinks=true, linkcolor=blue}
\usepackage{titlesec}
\titleformat{\chapter}[display]{\Large\centering}{Chapter \thechapter:}{0pt}{}{}
\titleformat{\section}{\large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}{\large\bfseries}{\thesubsubsection}{1em}{}
\pagestyle{fancy}
\fancyhead[RE,RO]{}
\fancyhead[LO,RE]{\itshape \nouppercase \leftmark}
\usepackage{float}
\restylefloat{table}
\usepackage[table]{xcolor} 
\setlength{\arrayrulewidth}{1mm}  
\renewcommand{\arraystretch}{1.2} 
\setlength{\tabcolsep}{0.5cm} 
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{array}
\usepackage{lmodern}
\usepackage{microtype} 
\usepackage{siunitx}
\begin{document}
\begin{table}[h]
\caption{Parameters}
\begin{tabular}{ p{6cm} p{4cm} p{4cm}  }    
\hline \\ 
\textsc{Demo 1} \\
Characteristics & \textsc{Water} & \textsc{Air}    \\ 
\hline 
Density & 1000 & 1.25 \\
State  &  liquid & Gas \\
\hline
\end{tabular}
\caption*{Table 1}
\label{table1}
\end{table}
\end{document}

In the above table I would like to make reference to the table using the "table1" label in the code. However, when I use \ref{table1}, it does not seem to refer me to the table. Also, The first caption on top (\caption{Parameters}) does not seem to appear in my table. I would really appreciate any help with these issues. I must be missing something quite obvious.

Thanks

8
  • 1
    There some compilation errors... please fix your MWE first. You use two captions for the table. Why \linespread{} before \documentclass?
    – user31729
    Commented Oct 22, 2014 at 14:39
  • @ChristianHupfer, sry about that, I've removed the bugs, it should compile now. I've also changed the position of linespread.
    – John_dydx
    Commented Oct 22, 2014 at 14:56
  • 1
    Did you compile multiple times?
    – Johannes_B
    Commented Oct 22, 2014 at 15:01
  • @John, restylefloat{table} screws up the positioning, two times \usepackage{caption} is useless
    – user31729
    Commented Oct 22, 2014 at 15:01
  • 1
    @Sverre, thanks for your suggestion. Your point has been noted and I've also read the website.
    – John_dydx
    Commented Oct 22, 2014 at 21:12

2 Answers 2

2

\restylefloat causes the caption positioning problem and \label after \caption*{} is useless!

\documentclass[12pt]{report}
\linespread{}
\usepackage{fancyhdr}
\usepackage{amsmath,amssymb}
\usepackage{relsize}
\usepackage[font={small,it}]{caption}
\usepackage{listings}
\usepackage{color} 
\definecolor{mygreen}{RGB}{28,172,0} 
\definecolor{mylilas}{RGB}{170,55,241}
\usepackage[titletoc,toc]{appendix}
\usepackage{graphicx}
\usepackage{setspace}  
\usepackage{changepage}
\usepackage[textwidth=16cm,textheight=24cm,margin=2cm]{geometry}
\usepackage[colorlinks,citecolor=red]{hyper ref}
\hypersetup{colorlinks=true, linkcolor=blue}
\usepackage{titlesec}
\titleformat{\chapter}[display]{\Large\centering}{Chapter \thechapter:}{0pt}{}{}
\titleformat{\section}{\large\bfseries}{\thesection}{1em}{}
\titleformat{\subsection}{\large\bfseries}{\thesubsection}{1em}{}
\titleformat{\subsubsection}{\large\bfseries}{\thesubsubsection}{1em}{}
\pagestyle{fancy}
\fancyhead[RE,RO]{}
\fancyhead[LO,RE]{\itshape \nouppercase \leftmark}
\usepackage{float}
%\restylefloat{table}
\usepackage[table]{xcolor} 
\setlength{\arrayrulewidth}{1mm}  
\renewcommand{\arraystretch}{1.2} 
\setlength{\tabcolsep}{0.5cm} 
\usepackage{booktabs}
\usepackage{tabularx}
\usepackage{array}
\usepackage{lmodern}
\usepackage{microtype} 
\usepackage{siunitx}

\begin{document}

\begin{table}[h]
\caption{Parameters}
\begin{tabular}{ p{6cm} p{4cm} p{4cm}  }    
\hline \\ 
\textsc{Demo 1} \\
Characteristics & \textsc{Water} & \textsc{Air}    \\ 
\hline 
Density & 1000 & 1.25 \\
State  &  liquid & Gas \\
\hline
\end{tabular}
%\caption*{Table 1}
\label{table1}
\end{table}


\begin{table}[h]
\begin{tabular}{ p{6cm} p{4cm} p{4cm}  }    
\hline \\ 
\textsc{Demo 1} \\
Characteristics & \textsc{Water} & \textsc{Air}    \\ 
\hline 
Density & 1000 & 1.25 \\
State  &  liquid & Gas \\
\hline
\end{tabular}
\caption*{Parameters}
\label{table2} %%% Useless -- done on purpose here!!!
\end{table}
Table \ref{table1} and another Table \ref{table2} has no influence
\end{document}

enter image description here

2
  • No comments please on \label after \caption*{} -- this is done on purpose to show the problem
    – user31729
    Commented Oct 22, 2014 at 15:06
  • Thanks Christian, it works well now. I'm glad I've learned something new about latex.
    – John_dydx
    Commented Oct 22, 2014 at 15:31
2

Remove these two lines:

\usepackage{float}
\restylefloat{table}

You are back in business.

1
  • Damn,you were quicker ;-)
    – user31729
    Commented Oct 22, 2014 at 15:04

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .