Graphics, Figures & TablesWrong Table Numbering in Subsections

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
palorama
Posts: 2
Joined: Wed Aug 24, 2011 11:54 pm

Wrong Table Numbering in Subsections

Post by palorama »

hello everyone,

I have been at this all day! It is not working for me. I am working on my thesis and in my chapter 3, subsection 3.3.1 my tables come up with \ref and caption and labels (in the correct order, caption first) as 3.1 (my section number). This is the case for the 12 tables I have in this chapter.

I have tried EVERYTHING (various packages, changing order, deleting .aux, .lot files, compiling 1000 times, running it line by line, searching through all the forums) and I don't get it. I must be doing something wrong! I am calling on your wisdom! I included here my preamble and my table (they are in a separate tex file since the main document "calls" the chapter 3.

Thank you for your help, I will forever grateful!!

Code: Select all

\documentclass[12pt,titlepage,twosided]{book}
\usepackage{amsmath}
\setcounter{secnumdepth}{4}
\setcounter{tocdepth}{3}
\usepackage{setspace}
\doublespace
\usepackage[table]{xcolor}
\usepackage{url}
\usepackage{hyperref}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{rotating}
\usepackage{graphicx}
\usepackage{parskip}
\usepackage{natbib}
\usepackage{eso-pic}
\usepackage[top=1in, bottom=1.5in, left=1in, right=1in]{geometry}
\usepackage{array}
\usepackage{fancyhdr}
%\usepackage{showkeys} %This package allows me to find keys and labels I have inserted in my document. I will need to remove once I am completely done with the document.
\usepackage[compact]{titlesec}
\titlespacing{\section}{0pt}{1ex}{0.5ex}
\titlespacing{\subsection}{0pt}{0.5ex}{0ex}
\titlespacing{\subsubsection}{0pt}{0ex}{0ex}
\pagestyle{fancy}


\begin{document}


\mainmatter

\renewcommand{\chaptername}{} 

\include{3/chapter3}

....

\subsection{Why? Results III  \label{subsec: why}}

 \begin{table} \footnotesize
\caption{Distribution \label{table: how } }
\vspace{0.5cm}
\begin{center}
\begin{tabular}{c c c}
\hline
\hline

\textbf{Observations} & \textbf{Number of patterns} & \textbf{Percentage$^b$ of observed} \\
\\
\hline
\hline
\\
\bf{1} & 2 & 2\\
\\
\bf{2} & 2 & 2\\
\\
\bf{3} & 2 & 2\\
\\
\bf{4} & 2 & 2\\
\hline
\bf{Total} & 2 & 100.0\\
\hline
\hline
\multicolumn{3}{l}{\scriptsize $^a$Codes includedr}\\
\multicolumn{3}{l}{\scriptsize $^b$Percentages have been rounded.}\\

\end{tabular}
\end{center}
\end{table}

....

\end{document}
Last edited by localghost on Thu Aug 25, 2011 11:11 am, edited 1 time in total.

Recommended reading 2024:

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

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

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

Wrong Table Numbering in Subsections

Post by localghost »

Never put a label into a caption. You better put it completely right behind.

Code: Select all

\caption{Distribution}\label{tab:how}
This applies to all commands that support labels (e. g. sectioning commands).


Best regards and welcome to the board
Thorsten
User avatar
sommerfee
Posts: 503
Joined: Mon Apr 09, 2007 4:20 pm

Wrong Table Numbering in Subsections

Post by sommerfee »

localghost wrote:Never put a label into a caption.
Why?

Laslie Lamport writes: "A label can appear in the argument of a sectioning or \caption command, but in no other moving arguments."

Edit: Typo
Last edited by sommerfee on Thu Aug 25, 2011 4:54 pm, edited 1 time in total.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Wrong Table Numbering in Subsections

Post by localghost »

sommerfee wrote:[…] Leslie Lamport writes: "A label can appear in the argument of a sectioning or \caption command, but in no other moving arguments."
Obviously I was mistaken. I remember to run into problems with some labels in the past and referred that to this case.
palorama
Posts: 2
Joined: Wed Aug 24, 2011 11:54 pm

Re: Wrong Table Numbering in Subsections

Post by palorama »

Thanks for the note. I have tried both ways and results are the same. I came across several posts that suggested it was good practice to do the label inside the caption. Any other suggestions? I bet 20$ with my husband that he would not find a solution before you all would! Thanks! :D
User avatar
Stefan Kottwitz
Site Admin
Posts: 10348
Joined: Mon Mar 10, 2008 9:44 pm

Re: Wrong Table Numbering in Subsections

Post by Stefan Kottwitz »

Hi palorama,

if you would like to get a solution it would be good if you would post a compilable example which shows the problem, so we could reproduce and fix the problem.
When I make this code compilable and copy and paste the first table to get more tables, they are numbered 3.1, 3.2, 3.3 - correctly one after another, per chapter. So one could just guess what might be the problem in your other code you did not post yet.

Stefan
LaTeX.org admin
Post Reply