如何在页脚中用两行显示较长的章节名称?

如何在页脚中用两行显示较长的章节名称?

不久前我问过这个问题调整章节部分的宽度。

但是页脚还有一个问题。如果章节名称太长,页脚中的章节名称会在中间结束。有没有可能将高度优化为两行?

Chapter name

Footer

我尝试制作一个工作样本,但它不是最佳的......

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}
\usepackage{fancyhdr} 
\usepackage{tgheros}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

\newcommand\mychapformat[1]{%
  \parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
  {\usekomafont{chapter}}%
  {\vspace{-8em}\raggedleft{%
    {\color{ctcolorchapterline}%
        \rule[-5pt]{2pt}{5cm}}\quad%
    {\color{ctcolorchapternum}
        \fontsize{60}{60}\selectfont\thechapter}%
    }%
  }%
  {-2.1em}%
  {\mychapformat}%
  [\phantomsection]

% **************************************************
% Header and Footer
% **************************************************
\pagestyle{fancy}
\renewcommand{\chaptermark}[1]{%
    \markboth{%
        \footnotesize%
        {\color{ctcolorchapterline}\textbf{\chaptername\ \thechapter}}%
        \quad%
        {\color{ctcolorchapterline}#1}%
    }{}%
}
\renewcommand{\sectionmark}[1]{%
    \markright{%
        \footnotesize%
        {\color{ctcolorchapterline}\textbf{\thesection}}%
        \quad%
        {\color{ctcolorchapterline}#1}%
    }%
}
%
\fancypagestyle{plain}{%
    \fancyhf{}
    \fancyfootoffset[OR]{1.85cm}
    \fancyfoot[OR]{%
        {\ }\usekomafont{chapter}%
        {\color{ctcolorchapterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{10pt}\begin{minipage}[b]{1.5cm}%
            \color{ctcolorchapterline}\normalsize\textbf{\thepage}%
        \end{minipage}%
    }
    \fancyfootoffset[EL]{1.85cm}
    \fancyfoot[EL]{%
        \usekomafont{chapter}%
        \begin{minipage}[b]{1.5cm}%
            \raggedleft\color{ctcolorchapterline}\normalsize\textbf{\thepage}%
        \end{minipage}%
        \hspace*{10pt}{\color{ctcolorchapterline}\rule[-90pt]{1.25pt}{100pt}}%
    }
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}
%
\fancypagestyle{maincontentstyle}{%
    \pagestyle{plain}
    \fancyhf{}
    \fancyfootoffset[OR]{1.85cm}
    \fancyfoot[OR]{%
        {\ }\usekomafont{chapter}\footnotesize%
        \rightmark%
        \hspace*{0.75cm}{\color{ctcolorchapterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{10pt}\begin{minipage}[b]{1.5cm}%
            \color{ctcolorfooterpage}\normalsize\textbf{\thepage}%
        \end{minipage}%
    }
    \fancyfootoffset[EL]{1.85cm}
    \fancyfoot[EL]{%
        \usekomafont{chapter}\footnotesize%
        \begin{minipage}[b]{1.5cm}%
            \raggedleft\color{ctcolorchapterline}\normalsize\textbf{\thepage}%
        \end{minipage}%
        \footnotesize%
        \hspace*{10pt}{\color{ctcolorchapterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{0.75cm}\leftmark%
    }
}

\begin{document}

\chapter{A test chapter with a long title that will span two lines}
\lipsum[1-6]

\end{document}

答案1

你想要这样的东西吗?

Footer - multiline

\documentclass{scrbook}
\usepackage{xcolor}
\usepackage{titlesec}
\usepackage{lmodern}% just for the example
\usepackage{lipsum}% just for the example
\usepackage{hyperref}
\usepackage{fancyhdr}
\usepackage{tgheros}
\usepackage{layout}

\colorlet{ctcolorchapterline}{cyan}
\colorlet{ctcolorchapternum}{cyan}

\newcommand\mychapformat[1]{%
  \parbox[b]{\dimexpr\textwidth-3em\relax}{\raggedright#1}}
\titleformat{\chapter}[display]%
  {\usekomafont{chapter}}%
  {\vspace{-8em}\raggedleft{%
    {\color{ctcolorchapterline}%
        \rule[-5pt]{2pt}{5cm}}\quad%
    {\color{ctcolorchapternum}
        \fontsize{60}{60}\selectfont\thechapter}%
    }%
  }%
  {-2.1em}%
  {\mychapformat}%
  [\phantomsection]

% **************************************************
% Header and Footer
% **************************************************
\renewcommand{\chaptermark}[1]{%
    \markboth{%
        \footnotesize%
        {\color{ctcolorchapterline}\textbf{\chaptername\ \thechapter}}%
        \quad%
        {\color{ctcolorchapterline}#1}%
    }{}%
}
\renewcommand{\sectionmark}[1]{%
    \markright{%
        \footnotesize%
        {\color{ctcolorchapterline}\textbf{\thesection}}%
        \quad%
        {\color{ctcolorchapterline}#1}%
    }%
}
%
\fancypagestyle{plain}{%
    \fancyhf{}
    \fancyfootoffset[OR]{1.85cm}
    \fancyfoot[OR]{%
        {\ }\usekomafont{chapter}%
        {\color{ctcolorchapterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{10pt}\begin{minipage}[b]{1.5cm}%
            \color{ctcolorchapterline}\normalsize\textbf{\thepage}%
        \end{minipage}%
    }
    \fancyfootoffset[EL]{1.85cm}
    \fancyfoot[EL]{%
        \usekomafont{chapter}%
        \begin{minipage}[b]{1.5cm}%
            \raggedleft\color{ctcolorchapterline}\normalsize\textbf{\thepage}%
        \end{minipage}%
        \hspace*{10pt}{\color{ctcolorchapterline}\rule[-90pt]{1.25pt}{100pt}}%
    }
    \renewcommand{\headrulewidth}{0pt}
    \renewcommand{\footrulewidth}{0pt}
}
%
\newlength{\mychapbox}
\setlength{\mychapbox}{\textwidth}
\addtolength{\mychapbox}{-1.5em}
\addtolength{\mychapbox}{-0.75cm}
\addtolength{\mychapbox}{-10pt}
\fancypagestyle{maincontentstyle}{%
    \pagestyle{plain}
    \fancyhf{}
    \fancyfootoffset[OR]{1.85cm}
    \fancyfoot[OR]{%
        {\ }\usekomafont{chapter}\footnotesize%
        \rightmark%
        \hspace*{0.75cm}{\color{ctcolorchapterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{10pt}\begin{minipage}[b]{1.5cm}%
            \color{ctcolorfooterpage}\normalsize\textbf{\thepage}%
        \end{minipage}%
    }
    \fancyfootoffset[EL]{1.85cm}
    \fancyfoot[EL]{%
        \usekomafont{chapter}\footnotesize%
        \begin{minipage}[b]{1.5cm}%
            \raggedleft\color{ctcolorchapterline}\normalsize\textbf{\thepage}%
        \end{minipage}%
        \footnotesize%
        \hspace*{10pt}{\color{ctcolorchapterline}\rule[-90pt]{1.25pt}{100pt}}%
        \hspace*{0.75cm}%
        \begin{minipage}[t]{\mychapbox}%
            \raggedleft\usekomafont{chapter}\color{ctcolorchapterline}\footnotesize\leftmark%
        \end{minipage}%
    }
}
\pagestyle{maincontentstyle}

\begin{document}

\chapter{A test chapter with a long title that will span two lines}
\lipsum[1-6]

\end{document}

相关内容