如何定义显示当前((sub)sub)部分的页码?

如何定义显示当前((sub)sub)部分的页码?

我尝试在页脚中打印该部分(带有(子)子部分)。为此,我定义了一个新的页码。它在前四页上工作正常,但在最后一页上却不行……目标是在每一页上都打印“第 x 节”,其中 x 恰好是封闭((子)子)节的编号。

\documentclass{scrartcl}

\usepackage{scrpage2}
\pagestyle{scrheadings}
\clearscrheadfoot

% page number (omitting trailing zeros)
\newcommand{\mypagenumber}{%
  \ifnum\value{subsubsection}=0
    \ifnum\value{subsection}=0
      \ifnum\value{section}=0
        % nothing
      \else
        Section~\thesection% e.g. 2
      \fi
    \else
      Section~\thesubsection% e.g. 2.1
    \fi
  \else
    Section~\thesubsubsection% e.g. 2.1.3
  \fi
}

\ofoot{\mypagenumber}

\begin{document}
\section{Section}
\clearpage
\subsection{Subsection}
\clearpage
\subsubsection{Subsubsection}
\clearpage
\subsubsection{Subsubsection}
\clearpage
\section{Section}
This page should only show ``Section 2'' (not ``Section 2.0.2'')
\end{document}

以下是解决 Christian 所提问题的更新。不过,它要求章节后面不能直接跟有子章节。

\newcommand{\mypagenumber}{%
  \ifnum\value{subsubsection}=0
    \ifnum\value{subsection}=0
      \ifnum\value{section}=0
        % nothing
      \else
        Section~\thesection% e.g. 2
      \fi
    \else
      Section~\thesubsection% e.g. 2.1
    \fi
  \else
    \ifnum\value{subsection}=0
      Section~\thesection% e.g. 2
    \else
      Section~\thesubsubsection% e.g. 2.1.3
    \fi
  \fi
}

答案1

以下内容摘自仅当节数 > 0 时才显示标题。 您可以使用

\renewcommand{\sectionmark}[1]{%
  \markright{#1\ \thesection}%
}
\renewcommand{\subsectionmark}[1]{%
  \markright{#1\ \thesubsection}%
}
\renewcommand{\subsubsectionmark}[1]{%
  \markright{#1\ \thesubsubsection}%
}

\ofoot{\rightmark}

这将显示分区单元(如上所述#1)。如果您只想要Section,则将 全部 替换#1Section

使用 可\rightmark避免在分段单元开始时调用分页算法时出现的问题。这可能会导致计数器在分段最终未结束的页面上递增。使用\rightmark包含的分段表示(\thesection\thesubsection\thesubsubsection)可避免此问题。

答案2

我从\ifnum风格转变为\ifnumexpr使用etoolbox

\documentclass{scrartcl}

\usepackage{scrpage2}
\usepackage{etoolbox}
\pagestyle{scrheadings}

\clearscrheadfoot



% page number (omitting trailing zeros)

% This uses the direct counter formatting, but should not be applied,
% The checking of counter values is the same as in \mypagenumber, where
% the formatting commands \the... are used.

\newcommand{\myotherpagenumber}{%
Section~
\ifnumequal{\number\value{subsubsection}}{0}{% subsubsection = 0 then remove subsubsection counter from output
\ifnumequal{\number\value{subsection}}{0}{% subsection = 0, then remove subsection from output
  \arabic{section}}{% No, subsection \neq 0
  \arabic{section}.\arabic{subsection}
}{% No subsubsection \neq 0, now check again for subsection = 0
\ifnumequal{\number\value{subsection}}{0}{% Yes, subsection = 0, remove it from output
  \arabic{section}}{% No, subsubsection \neq 0, show all three counter values. 
  \arabic{section}.\arabic{subsection}.\arabic{subsubsection}}}
}% End of outer \ifnumequal{subsubsection}...
}% End of command. 


\newcommand{\mypagenumber}{%
Section~
\ifnumequal{\number\value{subsubsection}}{0}{%
\ifnumequal{\number\value{subsection}}{0}{\thesection}{\thesubsection}%
}{\ifnumequal{\number\value{subsection}}{0}{\thesection}{\thesubsubsection}}
}% End of command




\ofoot{\mypagenumber}

\begin{document}
\section{Section}
\clearpage
\subsection{Subsection}
\clearpage
\subsubsection{Subsubsection}
\clearpage
\subsubsection{Subsubsection}
\clearpage
\section{Section}
This page should only show ``Section 2'' (not ``Section 2.0.2'')
\end{document}

第二部分的整页,不含子部分和子子部分

编辑

\documentclass{scrartcl}

\usepackage{scrpage2}
\usepackage{etoolbox}
\usepackage{xcolor}


\pagestyle{scrheadings}

\clearscrheadfoot

% Save old \thesubsubsection command 

\let\LaTeXStandardTheSubSubsection\thesubsubsection
\renewcommand{\thesubsubsection}{%
\ifnumequal{\number\value{subsection}}{0}{% sub = 0
\arabic{section}.\arabic{subsubsection}}{%
\LaTeXStandardTheSubSubsection}%
}%

% Save old \thesubsection command 
\let\LaTeXStandardTheSubsection\thesubsection
\renewcommand{\thesubsection}{%
\ifnumequal{\number\value{subsection}}{0}{% drop sub = 0
}{%
\LaTeXStandardTheSubsection}%
}%



\newcommand{\myotherpagenumber}{%
Section~
\ifnumequal{\number\value{subsubsection}}{0}{% subsubsection = 0 then remove subsubsection counter from output
\ifnumequal{\number\value{subsection}}{0}{% subsection = 0, then remove subsection from output
  \arabic{section}}{% No, subsection \neq 0
  \arabic{section}.\arabic{subsection}
}{% No subsubsection \neq 0, now check again for subsection = 0
\ifnumequal{\number\value{subsection}}{0}{% Yes, subsection = 0, remove it from output
  \arabic{section}}{% No, subsubsection \neq 0, show all three counter values. 
  \arabic{section}.\arabic{subsection}.\arabic{subsubsection}}}
} 
} % End of command.

\newcommand{\mypagenumber}{%
Section~
\ifnumequal{\number\value{subsubsection}}{0}{%
\ifnumequal{\number\value{subsection}}{0}{\thesection}{\thesubsection}%
}{\ifnumequal{\number\value{subsection}}{0}{\thesection}{\thesubsubsection}}
}% End of command




\ofoot{\Huge \mypagenumber}


\begin{document}
\tableofcontents

\section{Section Number \textcolor{blue}{1}}
\subsubsection{ \textcolor{red}{I am actually a subsubsection and not a subsection ;-) -- my number is 1.1}}
\clearpage
\subsection{True first Subsection \textcolor{green}{1.1}}
\clearpage
\subsubsection{\textcolor{yellow}{True first subsubsection below 1.1}}
\clearpage
\subsubsection{\textcolor{yellow}{True second subsubsection below 1.1}}
%\subsubsection{Subsubsection}
\clearpage
\section{Section}
This page should only show ``Section 2'' (not ``Section 2.0.2'')
\end{document}

相关内容