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

I envision something like the following:

\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}

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

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

but it's better to use a specific macro.


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


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

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

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


enter image description here

  • 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? – Jonathan Komar Jan 21 '16 at 7:53
  • @macmadness86 No, the other code is better because you don't repeat code. – yo' Jan 21 '16 at 8:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.