使用 fancyhdr 在首页上设置特殊标题

使用 fancyhdr 在首页上设置特殊标题

我正在使用该fancyhdr包,需要根据以下要求配置我的标题:

  1. 首页页眉在右侧包含一个小图像;
  2. 所有页面的页眉都包含一条宽度为 8pt 的红色水平线,一直延伸到页面两侧的末尾;
  3. 第一页之后的所有页面的页眉都包含文档的标题(此部分已经起作用)。

为了实现这一点,第一页的页眉尺寸(headheight 参数?)需要比其他页面的页眉尺寸大。每次我成功解决了这个问题的一个方面,其他方面就会出错。

我最近收到以下错误信息:

“Fancyhdr 软件包警告:\headheight 太小(21.0pt):至少将其设置为 132.00504pt。我们现在将其设置为与文档其余部分一样大。但是,这可能会导致页面布局不一致。”

如果我将整个文档的页眉高度设为 133,那么一切都会按照我想要的方式运行,但我当然不能承受整个文档都使用这么大的页眉。我只希望第一页有这么大的页眉。

另一个选择是在第一页上做一些特别的事情,让图像位于右上角,并在其下方显示红色水平线/框。然后标题就可以从第二页开始(我相信这是默认设置)。

我需要制作许多具有相同样式的文档,因此我使用 .sty 文件来控制尽可能多的样式元素,然后在我制作的每个单独的 latex 文件中调用它。到目前为止,这种方法效果很好。我只是无法弄清楚这个标题问题。

一旦确定了页眉,我也需要对页脚做同样的事情。在页脚中,我只需要在第一页的页脚上放一大段文字。在所有其他页面上,我需要在页脚中放一点文字。在所有情况下,页脚文本上方都需要有一条细黑线(我相信这是默认设置)。

这是我的.sty 文件:

\usepackage{titlesec}
\usepackage{makecell}
\usepackage{framed, ifthen}
\usepackage{caption,seqsplit, graphicx,soul,color,verbatim, fancyhdr}
\usepackage[T1]{fontenc}
\usepackage{wrapfig,lipsum,booktabs,tabularx,bookman,enumitem}
\usepackage[table,xcdraw,dvipsnames]{xcolor}
\usepackage[margin=1.0in, headheight=21pt]{geometry}
% \usepackage[none]{hyphenat}

\usepackage[colorlinks = true,
            linkcolor = black,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = black]{hyperref}

\definecolor{shadecolor}{HTML}{FFEFEF}


%%%%%%%%%%%%%% Header/Footer programming start %%%%%%%%%%%%

%%%%%%%%%%%%%%%
\newlength{\seplinewidth}
\newlength{\seplinesep}
\setlength{\seplinewidth}{8pt}
\setlength{\seplinesep}{.75in}
\colorlet{sepline}{blue}
\newcommand*{\sepline}{%
  \par
  \vspace{\dimexpr\seplinesep+.5\parskip}%
  \cleaders\vbox{%
    \begingroup % because of color
      \color{sepline}%
      \hrule width 2in height\seplinewidth
    \endgroup
  }\vskip\seplinewidth
  \vspace{\dimexpr\seplinesep-.5\parskip}%
}
% %%%%%%%%%%%%%%%


% \setlength{\headheight}{60pt}
%\renewcommand{\sectionmark}[1]{\gdef\currsection{#1}}
%\renewcommand{\subsectionmark}[1]{\markright{\currsection\ \textbullet\ #1}}
%\fancyhead[L]{ \nouppercase{\rightmark} \\}

% \rhead{\ifthenelse{\value{page}=1}{firstpage \\}{second page and after \\}}

\fancypagestyle{firstpage}{
  \fancyhf{}
  \fancyhead[R]{{\raisebox{\dimexpr-\height+\baselineskip}[0pt][0pt]{\includegraphics[width=2.5in]{GHELI_Logo1.png}}} \sepline}
}

\fancypagestyle{otherpages}{

%\pagestyle{fancy}
\fancyhf{}

\let\runtitle\@title
\lhead{\ifthenelse{\value{page}=1}{}{\runtitle} \vspace{8pt}}

% \rhead{\ifthenelse{\value{page}=1}{\includegraphics[width=6cm]{GHELI_Logo1.png}}{}}

\renewcommand{\headrulewidth}{8pt}
%\renewcommand{\headrule}{\hbox to \paperwitdh{\color{red}\leaders\hrule height \headrulewidth\hfill}}

%\rhead{\begin{picture}(0,0) \put(0,0){\includegraphics[width=6cm]{GHELI_Logo1.png}} \end{picture}}

% Length to control the \fancyheadoffset and the calculation of \headline
% simultaneously
\newlength\FHoffset
\setlength\FHoffset{1cm}

\addtolength\headwidth{2\FHoffset}

\fancyheadoffset{\FHoffset}

% these lengths will control the headrule trimming to the left and right 
\newlength\FHleft
\newlength\FHright

% here the trimmings are controlled by the user
\setlength\FHleft{-1in}
\setlength\FHright{-1in}

% The new definition of headrule that will take into acount the trimming(s)
\newbox\FHline
\setbox\FHline=\hbox{\color{red}\hsize=\paperwidth%
  \hspace*{\FHleft}%
  \rule{\dimexpr\headwidth-\FHleft-\FHright\relax}{\headrulewidth}\hspace*{\FHright}%
}
\renewcommand\headrule{\vskip-.7\baselineskip\copy\FHline}
}

\pagestyle{otherpages}
%%%%%%%%%%%%%%%%%% Header/Footer end %%%%%%%%%%%%%%%%%%%%%

\setlength{\parindent}{0pt}
% \setlength{\parskip}{3pt}

\setcounter{secnumdepth}{0}

\renewcommand{\familydefault}{\sfdefault}
% can be \rmdefault \sfdefault \ttdefault


\titleformat{\section}
{\color{red}\normalfont\LARGE\bfseries}
{\color{red}\thesection}{1em}{}
\titleformat{\subsection}
{\color{red}\normalfont\large\bfseries}
{\color{red}\thesubsection}{1em}{}
\begin{comment}
% not sure if i can do this: \titleformat{\title}
\end{comment}

这是我的 .tex 文件:

\documentclass[twoside]{article}


 \title{\color{red} Section Guide 3}
 \author{Global Health Teaching Fellows Series 2018-19}
 \date{}

\usepackage{SectionStyle1}

\begin{document}

\captionsetup[table]{name=Box}

\maketitle
\thispagestyle{firstpage}

\tableofcontents

\section{Lesson Details}

\subsection{Purpose}

The purpose of this section guide is to help Teaching Fellows (TFs) lead their third 50-minute discussion section of the semester with their students.

\subsection{Section Outline}

\begin{enumerate} % [noitemsep]
%  \item Graphical Literacy Warm-Up (10 minutes)
  \item Check-In and Review (10 minutes)
  \item Zika Debate (40 minutes)
\end{enumerate}

\subsection{Required Student Preparation}

Students should read or prepare the following items:

\begin{itemize} % [noitemsep]
%  \setlength{\itemsep}{1pt}
%  \setlength{\parskip}{0pt}
%  \setlength{\parsep}{0pt}
  \item Zika Virus. World Health Organization 2016. \url{http://who.int/mediacentre/factsheets/zika/en/}.
  \item Landry C. Zika is Driving Up Demand for Abortion. Here's why it shouldn't. The Washington Post 2016; Nov 22. \url{http://washingtonpost.com/posteverything/wp/2016/11/22/zika-is-driving-up-demand-for-abortion-heres-why-it-shouldnt}.
  \item Double Trouble: Many of the Areas at Greatest Risk for the Zika Virus Score Low on Reproductive Health Indicators. Population Institute 2016. \url{http://populationinstitute.org/external/Zika_Report_Double_Trouble.pdf}.
  \item Learn additional information about assigned region.
  \item Consider the reproductive rights landscape of your assigned region based on the reading and brainstorm implications for the transmission or control of Zika virus.
\end{itemize}

\subsection{TF Preparation Checklist}

\begin{itemize}
  \item Prepare for the Zika Debate by assigning a region to the students. 
\end{itemize}

\section{Learning Goals}

\begin{enumerate}
  \item Describe the determinants of health (type and level) associated with emerging infectious diseases, such as zika.
  \item Participate in a policy debate about how health systems can respond to infectious disease threats.
  \item Provide examples of how contributions can be made in tackling infectious diseases from both the health and non-health sectors.
\end{enumerate}

\section{Procedure}

\subsection{Before Section Begins}

In section, students will debate about the issue of abortion services in one particular region or country. At the time that students are assigned to read the "Double Trouble" report to prepare for this section meeting, they should also be assigned a region to focus on for the debate activity that will occur in section. A number of regions are covered in Part 3 of the ``Double Trouble'' reading, any of which could be reasonably used in the debate. The TF can decide which region the entire section will focus on (or students could vote at the previous meeting). The rest of this guide is written with examples from the U.S. states of Texas and Florida, but the TF can easily adapt the provided procedure to another region. \\

This section guide is written for students to debate the following resolution: ``Increased access to abortion services is a critical health systems response to the spread of Zika virus in Texas and Florida.'' \\

TFs can use this topic with their students or choose a different one for the students to debate. TFs should become familiar beforehand with possible arguments for and against the debated-upon resolution. \\

Half of the students will argue for the resolution and half will argue against it. TFs can decide to assign students to teams ahead of time, such that students would only need to come prepared to argue for their own team; or TFs can assign students to teams in the section meeting itself, meaning that students would need to come prepared to debate both for or against the resolution. 

\subsection{Part 1: Check-In and Review}
(10 minutes)



\begin{shaded*}

\textbf{Activity goals}
\begin{itemize}
  \item Review any items from class or the reading assignment.
\end{itemize}

\end{shaded*}

Touch base with students to see if they have any questions about homeworks or major concepts that were discussed in class. This is meant to just be a chance for TFs to take the temperature of the room, so if people have a lot of burning questions, keep track of them and consider following up by e-mail, or if you have time after you get through today's activities, you can return to them. You could also spend this time reviewing a selected concept from class that you feel would be useful. \\

Students may also have questions about the report they read in preparation for the section, which you can answer during this time.


\subsection{Part 2:  Zika Debate}
(40 minutes)

\begin{shaded*}
\textbf{Activity goals}
\begin{itemize}
  \item Practice taking sides of a global health debate, understanding all viewpoints, and arguing in favor of or against a particular resolution or policy. 
  \item Understand how infectious disease control can intersect with other major health issues (in this case, Zika and reproductive rights)
\end{itemize}
\end{shaded*}

In this portion of the class, students will participate in a debate based on the assigned reading. An example based on the issue of abortion services in the U.S. states of Texas and Florida is provided below. However, TFs could use the same procedure to facilitate a debate on any topic or region of their choosing.  

\begin{enumerate}
  \item In class, present the following resolution: 

  \textbf{Increased access to abortion services is a critical health systems response to the spread of Zika virus in the Americas.} 

  \item Divide the class into a group in support of this resolution (called the ``pro'' or ``for'' team) and another in opposition (called the ``con'' or ``against'' team).

  \item Give the students 10-15 minutes to prepare their arguments. Remind students that all team members must present part of their team's argument or rebuttal. 

  \item Facilitate a debate between the two teams according to the following schedule:

  \begin{itemize}
    \item 3 minutes: Group in favor of the resolution (for) presents their case
    \item 3 minutes: Group in opposition (against) presents their case
    \item 5 minutes: Groups huddle to prepare rebuttal points
    \item 2 minute: Rebuttal by against team.
    \item 2 minute: Rebuttal by for team.
  \end{itemize}

  \item Once the debate is over, facilitate a group discussion addressing the key take away messages you want students to leave with. These include:

  \begin{itemize}
    \item The difference between primary and secondary prevention.

    \textit{In this case, primary prevention would be the availability of and access to contraception, whereas abortion would be a form of secondary prevention.}

    \item The trade-offs involved in a policy decision.

    \textit{Should funds go towards increased access to abortion services, blocking some of the social and environmental determinants of Zika, or to something else altogether?}

    \item How culture and politics influences public health discourse.

    \item The interplay between health and human rights.

    \item How social inequities contribute to the spread of infectious disease.

    \textit{For example, the different social determinants of contraceptive use and unintended pregnancies across different geographies, populations, and social classes.}

  \end{itemize}

\end{enumerate}


\end{document}

答案1

切勿滥用 headers 作为标题。这里有一个使用 package 的建议sclayer-scrpage

dfw标题页

我移动了一些包裹,但是它们基本都没动。

\documentclass[twoside]{article}


\usepackage{blindtext}
\usepackage[margin=1.0in, headheight=21pt]{geometry}
\usepackage[table,xcdraw,dvipsnames]{xcolor}
\usepackage{scrlayer-scrpage}
\KOMAoptions{headsepline=8pt:1.4\textwidth}
\setkomafont{headsepline}{\color{red}}
\ohead{\doctitle}
\usepackage{titlesec}
\usepackage{makecell}
\usepackage{framed, ifthen}
\usepackage{caption,seqsplit, graphicx,soul,color,verbatim, }
\usepackage[T1]{fontenc}
\usepackage{wrapfig,lipsum,booktabs,tabularx,bookman,enumitem}
% \usepackage[none]{hyphenat}


\definecolor{shadecolor}{HTML}{FFEFEF}



\usepackage[colorlinks = true,
            linkcolor = black,
            urlcolor  = blue,
            citecolor = blue,
            anchorcolor = black]{hyperref}

\setlength{\parindent}{0pt}
% \setlength{\parskip}{3pt}

\setcounter{secnumdepth}{0}

\renewcommand{\familydefault}{\sfdefault}
% can be \rmdefault \sfdefault \ttdefault


\titleformat{\section}
{\color{red}\normalfont\LARGE\bfseries}
{\color{red}\thesection}{1em}{}
\titleformat{\subsection}
{\color{red}\normalfont\large\bfseries}
{\color{red}\thesubsection}{1em}{}

\renewcommand{\maketitle}{
\vspace*{-2cm}
\thispagestyle{empty}
  \hfill\includegraphics[width=4cm,height=4cm]{example-image-16x9}
  {\color{red}\rule{1.2\textwidth}{8pt}}
  \begin{center}%
  \let \footnote \thanks
    {\LARGE \color{red} \sectitle \par}%
    \vskip 1.5em%
    {\large
      \doctitle
      \lineskip .5em%
      \par}%
  \end{center}%
  \par
  \vskip 1.5em
}

\newcommand{\sectitle}{Section Guide 3}
\newcommand{\doctitle}{Global Health Teaching Fellows Series 2018-19}
\begin{document}
\maketitle
\tableofcontents

\section{Lesson Details}

\subsection{Purpose}

The purpose of this section guide is to help Teaching Fellows (TFs) lead their third 50-minute discussion section of the semester with their students.
\blinddocument
\end{document}

相关内容