
我需要重現以下標頭格式:
請幫忙;我完全是 LaTeX 或 TeX 的初學者。我使用 LyX,這包含在文檔的序言中:
\usepackage{fancyhdr}
\usepackage{multicol}
\usepackage{graphics}
\def\headrule{{%
\if@fancyplain\let\headrulewidth\plainheadrulewidth\fi
\hrule\@height\headrulewidth\@width\headwidth\vskip2pt%
\hrule\@height\headrulewidth\@width\headwidth\vskip-\headrulewidth\vskip-4pt
}}
\pagestyle{fancy}
\fancypagestyle{plain}%{%
\fancyhf{} % clear all header and footer fields
\renewcommand{\headrulewidth}{0.4pt}
\fancyhead{\resizebox{2in}{!}{\includegraphics{logo.png}}}
\vskip10pt
\lhead{\bfseries Reporte de Desarrollo}
\rhead{\bfseries DES-001}
\lfoot{Por: A. Perez}
\cfoot{\thepage /2}
\rfoot{Departamento de Diseño}
\renewcommand{\footrulewidth}{0.4pt}
感謝塞繆爾·阿爾伯特的幫助。
答案1
這是我提出的解決方案。我新增了使用套件lastpage
來自動顯示最後頁碼。我將包更改graphics
為graphicx
具有我用來標註您的徽標的功能。該代碼將替換您所提供的代碼。
\usepackage{etoolbox}%
\usepackage{fancyhdr}%
\usepackage{multicol}%
\usepackage{graphicx}%
\usepackage{lastpage}%
%
\def\MyLogo{MyLogo.ext}%
\newlength\logoHeight%
\setlength{\logoHeight}{50pt}%
\def\textheadLeft {ss Technical Document}%
\def\textheadRight{TD-1}%
\def\textfootLeft {Por: A. Perez}%
\def\textfootRight{Departamento de Diseño}%
%
\makeatletter%
\headheight = 80pt%
\fancypagestyle{plain}{%
\fancyhf{}%
\fancyhead[C]{%
\fboxsep = 0pt
\hbox to \headwidth%
{%
\parindent = 0pt%
\hsize = \headwidth%
\hfil%
\vbox to \logoHeight%
{%
\vfil%
\includegraphics[keepaspectratio,height=\logoHeight,width=\headwidth]{\MyLogo}%
\vfil%
}%
\hfil%
}%
}%
\lfoot{\textfootLeft}%
\cfoot{\thepage / \pageref{LastPage}}%
\rfoot{\textfootRight}%
\renewcommand{\footrulewidth}{0.4pt}%
\renewcommand{\headrulewidth}{10pt}%
}%
%
\def\headrule{%
\hrule\@height\footrulewidth\@width\headwidth\vskip2pt%
\textbf{\textheadLeft}\hfill\textbf{\textheadRight}%
\vskip2pt\hrule\@height\footrulewidth\@width\headwidth%
}%
\makeatother%
%
\pagestyle{plain}%
編輯:
由於您是乳膠新手,我決定讓它變得更容易。您現在只需在套件加載後修改前幾行
Samuel,我使用了你的程式碼,但 Lyx 似乎陷入了某種循環。我將您的 MyLogo.ext 更改為 logo.png,這樣做正確嗎?
Mylogo.ext 確實應該替換為您的商標的路徑:
- 它可以是從系統根目錄開始的絕對路徑 (c:/.../logo.png)。
- 但是,它最好是源自文件
.tex
所屬資料夾的相對路徑,這樣,如果您移動所有這些,它仍然可以編譯。
例如,如果您要使用的映像已命名logo.png
並且位於images/
檔案所在資料夾的子資料夾中.tex
,則應使用下列行
\def\MyLogo{images/logo.png}%
另請注意,在這一切之前,您應該聲明您使用的文件類別。例如,在我用來嘗試此操作的文件中,我使用了報告文件類別。
\documentclass[10pt,a4paper,titlepage,oneside,onecolumn]{report}
最後,在此標題之後,您應該\begin{document}
跟上文檔本身。例如在我的測試文件中
\begin{document}
test
\end{document}
總而言之,我無法在 Lyx 下測試它,因為我使用了 Miktex 2.9 和 Texmaker 的組合,但我相信使用它的人會很友好地確認它是否有效。
也許最後一件事是我使用 Lualatex。由於示例中存在一些非嚴格的 ASCII 字符,因此可能會發生這種情況(儘管我並不這麼認為)。也許可以嘗試ñ
在第一步中刪除它,以確保它不是任何問題的原因。
最終解決方案
在檢查了塞繆爾·阿爾伯特建議的所有內容後,由於重複的信息,我結束了對代碼的修剪。由於 LyX 配置,ñ 字元不相關,但程式碼的其他部分是相關的。以下程式碼有效:
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{multicol}
\usepackage{lastpage}%
\usepackage{graphicx}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\providecommand{\tabularnewline}{\\}
\@ifundefined{date}{}{\date{}}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\MyLogo{logo.png}%
\newlength\logoHeight%
\setlength{\logoHeight}{50pt}%
\def\textheadLeft {Reporte de Desarrollo}%
\def\textheadRight{DES-001}%
\def\textfootLeft {Por: A. Perez}%
\def\textfootRight{Departamento de Diseño}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\headheight = 80pt%
\fancypagestyle{plain}{%
\fancyhf{}%
\chead{%
\fboxsep = 0pt
\hbox to \headwidth%
{%
\parindent = 0pt%
\hsize = \headwidth%
\hfil%
\vbox to \logoHeight%
{%
\vfil%
\includegraphics[keepaspectratio,height=\logoHeight,width=\headwidth]{\MyLogo}%
\vfil%
}%
\hfil%
}%
}%
\lfoot{\textfootLeft}%
\cfoot{\thepage / \pageref{LastPage}}%
\rfoot{\textfootRight}%
\renewcommand{\footrulewidth}{0.4pt}%
\renewcommand{\headrulewidth}{10pt}%
}%
%
\def\headrule{%
\hrule\@height\footrulewidth\@width\headwidth\vskip2pt%
\textbf{\textheadLeft}\hfill\textbf{\textheadRight}%
\vskip2pt\hrule\@height\footrulewidth\@width\headwidth%
}%
%
\pagestyle{plain}%