目錄中的動態章節名稱錯誤

目錄中的動態章節名稱錯誤

我想列印帶有前綴“附錄 A:[某些標題]”、“附錄 B:[某些其他標題]”...的附錄標題。

我使用了以下定義的命令(最後可運行的 tex-document ):

\newcounter{rsss}

\DeclareRobustCommand{\appendixString}{
    \setcounter{rsss}{\value{chapter}}
    \addtocounter{rsss}{- \value{chapterCounter}}
    Appendix\Alph{rsss} :
}
\DeclareRobustCommand{\appendixStringHeadline}{
    \setcounter{rsss}{\value{chapter}}
    \addtocounter{rsss}{- \value{chapterCounter}}
    \addtocounter{rsss}{1}
    Appendix \Alph{rsss} :
}

\DeclareRobustCommand{\appendix}[2]{
    \addchap[\appendixStringHeadline #1]{\appendixStringHeadline     #1}\label{#2}
    \ihead{
    \appendixString #1
    }
    \stepcounter{chapter}
}

這適用於標題和標題,但在目錄中,始終有“附錄 A”。我怎樣才能解決這個問題?我嘗試使用 手動設定 tableofcontents-name [],但這不起作用:/。感謝您的幫助 :)

可運行的 tex 文件

\documentclass{scrreprt}
\usepackage{scrpage2}\pagestyle{scrheadings}


\newcounter{chapterCounter}
\newcounter{rsss}

\DeclareRobustCommand{\appendixString}{
    \setcounter{rsss}{\value{chapter}}
    \addtocounter{rsss}{- \value{chapterCounter}}
    Appendix \Alph{rsss} :
}
\DeclareRobustCommand{\appendixStringHeadline}{
    \setcounter{rsss}{\value{chapter}}
    \addtocounter{rsss}{- \value{chapterCounter}}
    \addtocounter{rsss}{1}
    Appendix \Alph{rsss} :
}

\DeclareRobustCommand{\appendix}[2]{
    \addchap[\appendixStringHeadline #1]{\appendixStringHeadline     #1}\label{#2}
    \ihead{
        \appendixString #1
    }
    \stepcounter{chapter}
}
\begin{document}
\tableofcontents
\chapter{ Bla}
\chapter{ Bla Bla}
\appendix{test 1}{bla bla}
\appendix{test 2}{bla}

\end{document}

答案1

我不確定你為什麼要使用如此複雜的方法。

\documentclass{scrreprt}
\usepackage{scrpage2}

\pagestyle{scrheadings}

\newcommand{\appendixString}{Appendix \thechapter: }

\newcommand{\addappendix}[1]{%
  \refstepcounter{chapter}
  \addchap{\appendixString #1}%
  \ihead{\appendixString #1}%
}

\begin{document}
\tableofcontents

\chapter{Bla}
\chapter{Bla Bla}

\appendix

\addappendix{test 1}\label{bla bla}
\addappendix{test 2}\label{bla}

\end{document}

在此輸入影像描述

\appendix無論如何,重新定義並不是最好的選擇。

答案2

不要在 \addchap 的參數內設定計數器。

\documentclass{scrreprt}
\usepackage{scrpage2}\pagestyle{scrheadings}


\newcounter{chapterCounter}
\newcounter{rsss}

\DeclareRobustCommand{\appendix}[2]{%
    \clearpage
    \setcounter{rsss}{\value{chapter}}%
    \addtocounter{rsss}{- \value{chapterCounter}}%
    \addtocounter{rsss}{1}%
    \addchap[Anhang \Alph{rsss} : #1]{Anhang \Alph{rsss} :     #1}\label{#2}
    \ihead{%
        Appendix \Alph{rsss} : #1
    }%
    \stepcounter{chapter}
}
\begin{document}
\tableofcontents
\chapter{ Bla}
\chapter{ Bla Bla}
\appendix{test 1}{bla bla}
\appendix{test 2}{bla}

\end{document}

(我不明白為什麼你要使用所有這些額外的計數器,為什麼你不使用 KOMA-script 提供的章節前綴,以及為什麼你在文本中使用“Anhang”,但在標題中使用“Appendix”卻沒有不要更改這部分代碼。

相關內容