Document ClassesSection Numbering

Information and discussion about specific document classes and how to create your own document classes.
Post Reply
pengyau
Posts: 4
Joined: Wed Sep 08, 2010 10:34 pm

Section Numbering

Post by pengyau »

I am using a thesis.sty file written by previous students to write my thesis, and it contains the following:

\def\thesection {\Alph{section}}
\def\labelsection {\thesection.}

The section headings are automatically numbered A, B, C.

When I make reference to a section using \ref{sec:Ex}, I want to see 3.B for the 2nd section in Chapter 3. However, only the section number shows up, i.e., B without the chapter number. I tried to amend the above 2 lines with

\def\thesection {\thechapter.\Alph{section}}
\def\labelsection {\thechapter.\thesection.}

The reference with \ref{sec:Ex} works now, but the section headings also include the chapter number. How do I remove the chapter number?
Last edited by pengyau on Fri Sep 10, 2010 11:55 pm, edited 1 time in total.

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

ChemistKatie
Posts: 14
Joined: Wed Sep 01, 2010 4:47 pm

Section Numbering

Post by ChemistKatie »

I haven't been using latex for long so I am not an expert but have you tried:

Code: Select all

\def\thesection {\Alph{section}}
\def\labelsection {\thechapter.\thesection.}
Good luck!
meho_r
Posts: 823
Joined: Tue Aug 07, 2007 5:28 pm

Section Numbering

Post by meho_r »

You may use varioref package and redefine the look of references. E.g.:

Code: Select all

\usepackage{varioref}
\labelformat{section}{\thechapter.#1}
This code will typeset references exactly as you requested: chapter_number.section_number.
And here's a full example:

Code: Select all

\documentclass{report}

\renewcommand{\thesection}{\Alph{section}}
%\def\labelsection{\thechapter.\thesection}

\usepackage{varioref}
\labelformat{section}{\thechapter.#1}

\begin{document}

\tableofcontents

\chapter{A chapter}\label{ch:one}

Some text\ldots{}

\section{A section}\label{sec:one}

A reference:~\ref{sec:one}.

\section{Another section}

Some text\ldots{}

\section{And another one}\label{sec:two}

More references:~\ref{sec:two} and \ref{sec:one}.



\chapter{Another chapter}\label{ch:two}

Some text\ldots{} and references:~\ref{ch:one}, \ref{ch:two}, \ref{sec:one}, \ref{sec:two}.

\section{One more section}\label{sec:three}

\ldots{}and one more reference:~\ref{sec:three}.

\end{document}

pengyau
Posts: 4
Joined: Wed Sep 08, 2010 10:34 pm

Re: Section Numbering

Post by pengyau »

What meho_r suggested works like magic. Thanks.

I tried what ChemistKatie suggested as well, the problem with that is my section headings also include the chapter number, which I do not want.

Thanks all for your hints.
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Section Numbering

Post by localghost »

Now that the problem is solved, please be so kind and mark the topic accordingly as clearly described in Section 3 of the Board Rules (to be read before posting).


Best regards and welcome to the board
Thorsten
Post Reply