自定义标题,不使用 fancyhdr

自定义标题,不使用 fancyhdr

我想在我的章节中添加以下标题:

在此处输入图片描述

我不想使用 fancyhdr,因为当我使用它时,它会移动我之前的所有页面设置(主要是目录布局),我尝试使用 /thispagestyle{fancy},但它不起作用。

我的代码如下:

\documentclass[letterpaper,12pt,oneside,onecolumn,final,openany]{report}

\usepackage{alltt}
\usepackage{times}                   
\usepackage{graphicx}
\usepackage{listings}
\usepackage{apalike}
\usepackage{verbatim}
\usepackage[spanish]{babel}
\usepackage[left=2.7cm,top=2.5cm,right=2.2cm]{geometry}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{tocloft}

\AtBeginDocument{\renewcommand{\contentsname}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Contenido}}
\AtBeginDocument{\renewcommand{\listfigurename}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Lista de Figuras}}
\AtBeginDocument{\renewcommand{\listtablename}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Lista de Tablas}}

\pagestyle{myheadings}

\begin{document}

\pagenumbering{roman}
\tableofcontents
\clearpage
\listoffigures
\clearpage
\listoftables
\clearpage
\pagenumbering{arabic}

\thispagestyle{myheadings}

\chapter{Introduction}
\label{chap:intro}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis accumsan tempor. Etiam adipiscing gravida sollicitudin. Suspendisse potenti. Donec risus lectus, ultricies at varius in, accumsan quis sapien. Duis at arcu turpis, lacinia dapibus orci. Etiam pharetra turpis et diam volutpat in dapibus lorem facilisis. Vestibulum adipiscing, metus quis scelerisque pulvinar, purus quam iaculis felis, ac porta nulla justo nec dui. Donec condimentum pulvinar augue, varius placerat quam pharetra in. Vestibulum velit ante, feugiat imperdiet scelerisque in, posuere eu purus.

\section{Lorem ipsum}
\label{sec:intro:lorem}

Pellentesque sit amet dui non nunc venenatis tempus vel id libero. Etiam consectetur metus fringilla nibh 

\subsection{Ipsum}
\label{sec:intro:ipsum}

Etiam iaculis ante vitae diam egestas egestas. Nullam sed odio id mi consequat porttitor. Ut ut libero augue, 

\chapter{Things 2}
\label{chap:intro2}

\subsection{Pallentesque}
\label{sec:intro:pallen}

Pellentesque sit amet dui non nunc venenatis tempus vel id libero. Etiam consectetur metus fringilla nibh 

\end{document}

目前它看起来像这样:

在此处输入图片描述

有什么建议么?

答案1

我不想使用 fancyhdr,因为当我使用它时,它会移动我之前的所有页面设置(主要是目录布局),

您可以fancyhdr放心使用,这是最简单的方法。请看以下代码:

\documentclass[letterpaper,12pt,oneside,onecolumn,final,openany]{report}

\usepackage{alltt,fancyhdr}
\usepackage{mathptmx}
\usepackage{graphicx}
\usepackage{listings}
\usepackage{apalike}
\usepackage{verbatim}
\usepackage[spanish]{babel}
\usepackage[left=2.7cm,top=2.5cm,right=2.2cm,bottom=2.5cm,headsep=.5cm]{geometry}
\usepackage{titlesec}
\usepackage{titletoc}
\usepackage{tocloft}

\AtBeginDocument{\renewcommand{\contentsname}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Contenido}}
\AtBeginDocument{\renewcommand{\listfigurename}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Lista de Figuras}}
\AtBeginDocument{\renewcommand{\listtablename}{\hfill\rule{.7\textwidth}{3pt} \hspace*{.3\textwidth} \\ \hspace*{.3\textwidth} Lista de Tablas}}

\fancypagestyle{myheadings}{%
\fancyhead{}
\fancyhead[L]{\bfseries\itshape\nouppercase\leftmark}
\fancyhead[R]{\bfseries\nouppercase\thepage}
\renewcommand{\headrulewidth}{1pt}
\renewcommand{\footrulewidth}{0pt}
\addtolength{\headheight}{15pt}
}
\begin{document}

\pagenumbering{roman}
\tableofcontents
\clearpage
\listoffigures
\clearpage
\listoftables
\clearpage
\pagenumbering{arabic}

\pagestyle{myheadings}

\chapter{Introduction}
\label{chap:intro}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam convallis accumsan tempor. Etiam adipiscing gravida sollicitudin. Suspendisse potenti. Donec risus lectus, ultricies at varius in, accumsan quis sapien. Duis at arcu turpis, lacinia dapibus orci. Etiam pharetra turpis et diam volutpat in dapibus lorem facilisis. Vestibulum adipiscing, metus quis scelerisque pulvinar, purus quam iaculis felis, ac porta nulla justo nec dui. Donec condimentum pulvinar augue, varius placerat quam pharetra in. Vestibulum velit ante, feugiat imperdiet scelerisque in, posuere eu purus.

\section{Lorem ipsum}
\label{sec:intro:lorem}

Pellentesque sit amet dui non nunc venenatis tempus vel id libero. Etiam consectetur metus fringilla nibh
\clearpage

\subsection{Ipsum}
\label{sec:intro:ipsum1}

Etiam iaculis ante vitae diam egestas egestas. Nullam sed odio id mi consequat porttitor. Ut ut libero augue,
\clearpage
\subsection{Ipsum}
\label{sec:intro:ipsum2}

Etiam iaculis ante vitae diam egestas egestas. Nullam sed odio id mi consequat porttitor. Ut ut libero augue,

\chapter{Things 2}
\label{chap:intro2}

\subsection{Pallentesque}
\label{sec:intro:pallen}

Pellentesque sit amet dui non nunc venenatis tempus vel id libero. Etiam consectetur metus fringilla nibh

\end{document}

在此处输入图片描述

您可以看到 TOC 布局未发生任何变化。

笔记times您必须使用而不是过时的mathptmx

答案2

如果使用该包时问题出在标题的高度fancyhdr,请记住您可以使用该包重新定义标题的高度geometry

\usepackage[head=30pt,foot=...]{geometry}

您可以尝试这个高度和整个页面布局,以最大限度地减少使用的影响fancyhdr

相关内容