Text Formattingunwanted \thesection formatting in \ref

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
jm.meyer
Posts: 4
Joined: Mon Nov 09, 2009 5:25 pm

unwanted \thesection formatting in \ref

Post by jm.meyer »

Hi,
as you can see in the following example the output of \ref keeps formatting the sections number is as defined in
\renewcommand{\thesection}{\large\arabic{section}}.
example:

Code: Select all

\documentclass[a4paper,oneside,12pt]{scrreprt}

\renewcommand{\thesection}{\large\arabic{section}}

\begin{document}
\section{Foo}
\label{sec:foo}
\section{Faa}
The following number of the previous section is large: \ref{sec:foo}
\end{document}
I guess this is because for labels that refer to sections, \ref calls \thesection when it expands.
Any way to change the formatting of the output of \ref, without touching the formatting of the sections number (the one that come before the sections heading)?

PS.:I came up with this problem as a followup to another post of mine but i hope it's ok that i make a new topic for it, since this might be inteteresting for other people having the same question and it's easier to find this way

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

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

unwanted \thesection formatting in \ref

Post by gmedina »

Hi,

instead of redefining the \thesection command, I would use the titlesec package to change the size for the numbers used in the section headings. Using this approach, the \ref command won't notice the effect of the redefinition. Take a look at the following simple example:

Code: Select all

\documentclass[a4paper,oneside,12pt]{scrreprt}
\usepackage{titlesec}

\titleformat{\section}
  {\normalfont\Large\sffamily\bfseries}{\Huge\thesection}{.5em}{}
\titlespacing*{\section}
  {0pt}{3.5ex plus 1ex minus .2ex}{2.3ex plus .2ex}

\begin{document}

\chapter{Test chapter}
\section{Test section}\label{sec:test}

In the following reference to section \ref{sec:test}, the number has the normal size.

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
Post Reply