\ref を使用して moderncv クラスの番号付きセクションを参照します。

\ref を使用して moderncv クラスの番号付きセクションを参照します。

moderncvクラス内の番号付きセクションを参照したいのです\refが、それができません。

私は次のタイトルの投稿を読みました moderncv クラスで \ref を使用する そして、次のものを得ることができました:

\documentclass[11pt,a4paper]{moderncv}
\moderncvstyle{banking}
\moderncvcolor{blue}

\usepackage[margin=1in]{geometry}
\usepackage{etoolbox}
\newcounter{secnumber}
\newcommand{\numbersec}{\refstepcounter{secnumber}\thesecnumber~}
\patchcmd{\section}{\sectionstyle{#1}}{\sectionstyle{\numbersec #1}}{}{}

\renewcommand\sectionstyle[1]{{%
  \refstepcounter{secnumber}%
  \sectionfont
  \textcolor{color1}{\thesecnumber.\quad#1}%
}}

\firstname{First Name}
\familyname{Last Name}

\begin{document}

\makecvtitle

\section{A Section}
\label{sec.one}
Text goes here 

\section{Another Section}
\label{sec.two}
Text goes here 

\section{Yet Another Section}
\label{sec.three}

Recall in section \ref{sec.one} that we mentioned ...

\end{document}

これにより、次の出力が得られます。

ここに画像の説明を入力してください

ご覧のとおり、コマンドを使用する位置にセクション番号が表示されていません\ref

私は、この問題を解決するために、次のタイトルの投稿を読んでみました。moderncv クラスで \ref を使用する しかし、私は成功しませんでした。

\refクラスでラベル付けされた番号付きセクションを使用したり参照したりすることは可能ですかmoderncv?

注記:これは珍しいリクエストかもしれないと認識していますが、この質問をする理由は、すでにクラスを使用して CV を作成しておりmoderncv、番号付きセクションを必要とする補足文書も作成する必要があるためです。 CV と補足文書の視覚的およびスタイル的一貫性を維持するために、この補足文書にクラス (変更あり) を使用したいと思います。moderncv補足文書で参照を要求する理由は、読者に特定の番号付きセクションを参照するように要求することで、情報の繰り返しを避けるためです。

答え1

問題は、数値を生成するために使用されているかなり複雑なコードによるものです。そのコードを簡素化すれば、\labelコマンドは期待どおりに動作します。マクロ内でカウンタを増やす代わりに\sectionstyle、コマンドの前にカウンタを追加します。これにより、コマンドがマクロ内にある\sectionかどうかに関係なく、ラベルに適切にアクセスできます。\label\section{...}ます。

\documentclass[11pt,a4paper]{moderncv}
\moderncvstyle{banking}
\moderncvcolor{blue}

\usepackage[margin=1in]{geometry}
\usepackage{etoolbox}
\newcounter{secnumber}
\pretocmd{\section}{\refstepcounter{secnumber}}{}{}
\renewcommand\sectionstyle[1]{{%
  \sectionfont
  \textcolor{color1}{\thesecnumber.\quad#1}%
}}

\firstname{First Name}
\familyname{Last Name}

\begin{document}

\makecvtitle

\section{A Section}
\label{sec.one}
Text goes here 

\section{Another Section}
\label{sec.two}
Text goes here 

\section{Yet Another Section}
\label{sec.three}

Recall in section \ref{sec.one} that we mentioned and in section \ref{sec.two} ... and in section \ref{sec.three} we see

\end{document}

コードの部分的な出力

関連情報