2

I cannot refer to a section or subsection in the main text of my overleaf document using this command:

Section~\label{sec:X}

I am sharing the code of the document below and it gives the following result:

I want to place the reference here, Section.

\documentclass[12pt,aps,prl,letterpaper,superscriptaddress]{revtex4-2}
\begin{document}

\section{S2. How to make a section}
\label{sec:buildsection}

I want to place the reference here, Section~\ref{sec:buildsection}


\end{document}
13
  • your posted code is not an example of the problem you are asking about. Show an example with a section reference that does not work, then we can debug it Nov 1, 2022 at 16:06
  • Please have a look at the code now, after \begin{document}
    – Ali Babar
    Nov 1, 2022 at 16:11
  • \section{S2. How to make a section} \label{sec:buildsection} I want to place the reference here, Section~\label{sec:buildsection}
    – Ali Babar
    Nov 1, 2022 at 16:12
  • 1
    @daleif it was revtex until the last edit (and I can reproduce now) Nov 1, 2022 at 16:27
  • 1
    I am using \documentclass[12pt,aps,prl,letterpaper,superscriptaddress]{revtex4-2} I have edit the question and added it there also.
    – Ali Babar
    Nov 1, 2022 at 16:28

1 Answer 1

5

With the options you used the class uses unnumbered sectioning commands. You can't reference them automatically, but have to do it manually as you did it in the title text:

\documentclass[12pt,aps,prl,letterpaper,superscriptaddress]{revtex4-2}

\begin{document}
\section{S2. How to make a section}\label{sec:buildsection}


I want to place the reference here, Section~S2

\end{document}

You could change the secnumdepth counter to get numbered sections and then references would work. But normally it is not a good idea to change the layout of a journal class, they want it as it is.

\documentclass[12pt,aps,prl,letterpaper,superscriptaddress]{revtex4-2}
\setcounter{secnumdepth}{3}
\begin{document}
\section{S2. How to make a section}\label{sec:buildsection}


I want to place the reference here, Section~\ref{sec:buildsection}

\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .