使用 \ref 或 \autoref 来格式化特殊章节

使用 \ref 或 \autoref 来格式化特殊章节

我有一个严格的布局,这就是为什么我有特殊的格式。不幸的是,\autoref{} 和 \ref{} 都不能正常工作。我创建了一个 MWE - 不幸的是它不是那么小。

\documentclass{scrbook}

\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}

\usepackage{ifthen}

\newlength{\sectionbaselineskip}
\setlength{\sectionbaselineskip}{\baselineskip}

\usepackage{tocloft}
\usepackage{mdframed}

\definecolor{SectionGray}{gray}{0.85}
\definecolor{BlockGray}{gray}{0.4}

\usepackage[linktoc=none]{hyperref}

\newenvironment{JustLeft}[1][\textwidth]
{\begin{minipage}[t]{#1}\begin{flushleft}}
        {\end{flushleft}\end{minipage}}

\newenvironment{Spalten}
{\raggedcolumns%
    \begin{multicols}{2}%
        \thispagestyle{net}
        \setlength{\parskip}{1\baselineskip}%
        \setlength{\parindent}{0pt}%
        \setlength{\parsep}{0pt}%
    }
    {\end{multicols}}

\newlength{\secboxlen}
\newlength{\sectextlen}
\newcounter{mylinecounter}
\setlength{\fboxsep}{0pt}

\newcommand{\SectionKopf}{\rule{0pt}{2.4ex}}
\newcommand{\SectionFuss}{\rule[-1.1ex]{0pt}{1ex}}

\newcommand{\TheSection}[3][n]{%
    %           ===========
    \setlength{\secboxlen}{\linewidth}%
    \addtolength{\secboxlen}{-2\fboxsep}%
    \setlength{\sectextlen}{\linewidth}%
    \addtolength{\sectextlen}{-1cm}%
    \stepcounter{section}%
    \makebox[0pt][l]{%
        \raisebox{0pt}[0pt][0pt]{%
            \colorbox{SectionGray}{%
                \begin{JustLeft}[\secboxlen]%
                    \fontsize{10pt}{\sectionbaselineskip}\selectfont%
                    \makebox[1mm]{}\bfseries\makebox[9mm][l]{\thesection}%
                    \begin{JustLeft}[\sectextlen]%
                        {\SectionKopf#3\SectionFuss}%
                    \end{JustLeft}%
            \end{JustLeft}}%
        }%
    }%
    \ifthenelse{\equal{#1}{b}}
    {% IF
        \addtocontents{toc}{\protect\renewcommand{\cftsecpagefont}{\bfseries}}%
        \addcontentsline{toc}{section}{\bfseries\numberline{\thesection}#3}%
        \addtocontents{toc}{\protect\renewcommand{\cftsecpagefont}{\mdseries}}%
    }%
    {% ELSE
        \addcontentsline{toc}{section}{\numberline{\thesection}#3}%
    }%
    \par%
    \setcounter{mylinecounter}{1}%
    \whiledo{\value{mylinecounter}<#2}{\nothing\\\stepcounter{mylinecounter}}%
    \nopagebreak %
}

\begin{document}
\TheSection{1}{first section}
\label{add}
\autoref{add}
\end{document}

使用此代码我得到

在此处输入图片描述

而不是“??”我想要部分编号 0.1

相关内容