# How can I expand the font size within a heading (section, subsection, etc.)?

I'd like to make a list of headings with their font sizes:

I envision something like the following:

\documentclass{article}
\begin{document}
\section{{\textbackslash}section \makeatletter\f@size pt\makeatother}
\subsection{{\textbackslash}subsection\makeatletter\f@size pt\makeatother}
\subsubsection{{\textbackslash}subsubsection\makeatletter\f@size pt\makeatother}
\paragraph{{\textbackslash}paragraph\makeatletter\f@size pt\makeatother}
\end{document}


I suspect this is an expansion problem. I saw this question: How could I check what font size is in pt for \section, \subsection, and \subsubsection?

But I would like to know why my code does not work.

-

Your code doesn't work because you're issuing \makeatletter at the wrong time; category codes are not changed when tokens have already been absorbed.

You need

\makeatletter
\section{\textbackslash section\f@size pt}
\makeatother


but it's better to use a specific macro.

\documentclass{article}

\newcommand{\cs}[1]{\textbackslash #1}
\makeatletter
\newcommand{\fs}{\f@size pt}
\makeatother

\begin{document}

\section{\cs{section}: \fs}

\subsection{\cs{subsection}: \fs}

\subsubsection{\cs{subsubsection}: \fs}

\end{document}


-
Thanks for the most recent edits, I was just wondering about wrapping the sections with \makeatletter and \makeatother. That solidified my understanding. I assume the reason why the other code is better is to keep all category code changes out of the body? – macmadness86 Jan 21 at 7:53
@macmadness86 No, the other code is better because you don't repeat code. – yo' Jan 21 at 8:13