LaTeX forum ⇒ GeneralCurrent chapter number variable Topic is solved

LaTeX specific issues not fitting into one of the other forums of this category.
ProbablyNotYou
Posts: 2
Joined: Mon Jul 08, 2024 8:44 am

Current chapter number variable

Postby ProbablyNotYou » Mon Jul 08, 2024 9:05 am

Hello,

I'm searching for a way to automatically set labels depending on in which chapter the labeled item is in. Something like a variable that contains the current chapter number, is what I'm looking for. I want to use a selfmade section, that is automatically labeled, so that I can reference it by:[chapternumber . sectionnumber] (In which the sectionnumber is the by me given number). It should look something like this, if \currentchapter contained the current chapter number:


\documentclass[11pt,titlepage,a4]{report}

\usepackage{hyperref}

\newcommand{\ownsection}[1]{\section{Definition #1}\label{\currentchapter.#1}}

\begin{document}

\chapter{Exponential Equations}

\ownsection{1}
something

\chapter{Next}

Exponential Equations are defined as in \hyperref[1.1]{Definition 1}.

\end{document}


In PDF I want it to look like:

Chapter 1
Exponential Equations


Definition 1
something


Chapter 2
Next


Exponential Equations are defined as in Definition 1.

I'm looking forward to any help :).
Thanks a lot!

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics
User avatar
Stefan Kottwitz
Site Admin
Posts: 10199
Joined: Mon Mar 10, 2008 9:44 pm

Current chapter number variable  Topic is solved

Postby Stefan Kottwitz » Mon Jul 08, 2024 11:10 am

Welcome to the forum!

You can use \thechapter:

\newcommand{\ownsection}[1]{\section{Definition #1}\label{\thechapter.#1}}


Stefan
LaTeX.org admin

ProbablyNotYou
Posts: 2
Joined: Mon Jul 08, 2024 8:44 am

Current chapter number variable

Postby ProbablyNotYou » Mon Jul 08, 2024 1:11 pm

Thank you for the fast answer!
It works like a charm, exactly as I wanted!


Return to “General”

Who is online

Users browsing this forum: Majestic-12 [Bot] and 4 guests