使用背景自定义 fancyhdr 页脚

使用背景自定义 fancyhdr 页脚

我正在尝试使用包自定义页脚的背景fancyhdr

这就是我现在所拥有的:

\documentclass{article}

\usepackage{fancyhdr}
\usepackage{calc}

\fancypagestyle{plain}{%
    \fancyhf{} % Clear all headers/footers
    \fancyfoot[L]{
        \textcolor{green}{\rule[-4pt]{\textwidth}{15pt}}%
        \hspace{-\textwidth}%
        \textcolor{red}{\setlength{\hspace}{0.5\textwidth-20pt}\thepage}} % Left footer page number
    \fancyfoot[R]{
        \textcolor{red}{Something\setlength{\hspace}{0.5\textwidth-20pt-\widthof{Something}}}} % Right footer company
    \renewcommand{\headrulewidth}{0pt} % 2pt header rule
    \renewcommand{\footrulewidth}{0pt} % No footer rule
}
\setlength{\headheight}{24pt}


\title{Title} % Title of the assignment

\author{Author Name\\ \texttt{[email protected]}}

\date{}

%----------------------------------------------------------------------------------------

\begin{document}

\maketitle

\section*{Introduction}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent porttitor arcu luctus, imperdiet urna iaculis, mattis eros. Pellentesque iaculis odio vel nisl ullamcorper, nec faucibus ipsum molestie. Sed dictum nisl non aliquet porttitor. Etiam vulputate arcu dignissim, finibus sem et, viverra nisl. Aenean luctus congue massa, ut laoreet metus ornare in. Nunc fermentum nisi imperdiet lectus tincidunt vestibulum at ac elit. Nulla mattis nisl eu malesuada suscipit.

\end{document}

在此处输入图片描述

两个问题:

  1. 如何仅为右页脚设置绿色背景,即仅使正确的一半的\textwidth绿色正确的页脚(并且没有背景左边页脚)?

  2. 如何以编程方式设置背景条的高度,以便即使页脚大小发生变化,右页脚也能在绿色条内垂直居中(但仍与左页脚保持水平)?目前,它是硬编码的。

答案1

这是你想要的吗?

\documentclass{article}
\usepackage{xcolor}
\usepackage{fancyhdr}
\usepackage{lipsum}

\fancypagestyle{plain}{%
    \fancyhf{} % Clear all headers/footers
    \fancyfoot[L]{%
 \makebox[\dimexpr0.5\textwidth-20pt][r]{\color{red}\thepage}} % Left footer page number
    \fancyfoot[R]{\colorbox{green}{\makebox[\dimexpr0.5\textwidth-6pt][l]{{}\hspace*{13pt}
        \color{red}Something}}} % Right footer company
    \renewcommand{\headrulewidth}{0pt} % 2pt header rule
    \renewcommand{\footrulewidth}{0pt} % No footer rule
}
\setlength{\headheight}{24pt}
    \pagestyle{plain}

\title{Title} % Title of the assignment

\author{Author Name\\ \texttt{[email protected]}}

\date{}

%----------------------------------------------------------------------------------------

\begin{document}

\maketitle

\section*{Introduction}

\lipsum[1-10]

\end{document} 

在此处输入图片描述

相关内容