我对 LaTeX 还很陌生,但我遇到了一个非常奇怪的问题,因为我需要在第一页上显示页眉,如屏幕截图所示。大学提供了一个矩形图像(链接这里),我认为使用 \includegraphics 会非常容易,但似乎很难以干净的方式做到这一点,而尝试复制粘贴代码似乎会给我带来我不想要的脏代码。遗憾的是 fancyhdr 手册没有显示任何将图像放入标题的示例,所以我不知道在哪里可以找到。
答案1
这是我的fancyhdr
解决方案集合中的一个示例。
\documentclass{article}
\usepackage[headheight=45pt, includehead]{geometry} % for margins on a A4paper
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{hyperref}
\usepackage{makecell}
\pagestyle{fancy}
\fancyhf{}
\newcommand{\headfont}{\fontsize{8}{9}\selectfont}
\fancypagestyle{plain}{
\fancyhf{}
\fancyhead[L]{%
\mbox{\makecell[cl]{\includegraphics[height=3\normalbaselineskip]{example-image}}}
\headfont
\makecell[cl]{%
Journal on Teaching Engineering, 1:1 (2015) 5-15 \\
ISSN XXX-XXXX \\
DOI: \href{https://doi.org/10.24840/2183-6493\_00X.00X\_00XX}{10.24840/2183-6493\_001.001\_0011}
}}
\fancyhead[R]{\headfont
\makecell[cr]{%
Received: XX December, XXX \\
Revised: XX December, XXX \\
Published: XX December, XXXX
}}
\fancyfoot[R]{\headfont\textbf{\thepage}}
}
\begin{document}
\pagestyle{plain}
\lipsum[1-3]
\end{document}
答案2
通过阅读大量有关 fancyhdr 和 makecell/minipage 的资料,我最终解决了主要问题。
我最终得到了一个非常令人满意的结果,但我觉得代码有些脏,可能有更好的解决方案(特别是对于小页面和表格中的多行)
\documentclass{article}
% Lingua
\usepackage[italian]{babel}
% Pagina e margini
\usepackage[a4paper,top=1.5cm,bottom=1cm,left=2cm,right=2cm]{geometry}
% Spacing
\linespread{1.15}
% Useful packages
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage[colorlinks=true, allcolors=blue]{hyperref}
\usepackage{fancyhdr}
\usepackage{makecell}
\usepackage[dvipsnames]{xcolor}
% Fonts
\usepackage{fontspec}
\setmainfont{Baskerville}[
Extension={.otf},
Path=./Fonts/,
UprightFont={*},
BoldFont={*-SemiBold},
ItalicFont={*-Italic},
BoldItalicFont={*-SemiBoldItalic}]
% Colors
\definecolor{rossovanvitelli}{rgb}{0.63529,0.11373,0.13333}
\setsansfont{Titillium}[
Extension={.otf},
Path=./Fonts/,
UprightFont={*},
BoldFont={*-SemiBold},
ItalicFont={*-Italic},
BoldItalicFont={*-SemiBoldItalic}]
% Header
\renewcommand{\headrulewidth}{0pt}
\setlength{\headheight}{110pt}
%\fancyhead[R]{}
\fancyhead[L]{
\color{rossovanvitelli}
\begin{minipage}{.5\textwidth}
\vspace*{5pt}
\includegraphics*[width=160pt]{Logo-Unicampania.pdf}% non c'è l'ambiente figure.
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{tabular}{p{0.5\textwidth}p{0.5\textwidth}}
\makecell[tl]{\fontsize{8pt}{8pt}\selectfont{Scuola di Medicina e}\\\fontsize{8pt}{8pt}\selectfont{Chirurgia}} &
\makecell[tl]{\fontsize{8pt}{8pt}\selectfont{Dipartimento di}\\\fontsize{8pt}{8pt}\selectfont{Scienze Mediche e}\\\fontsize{8pt}{8pt}\selectfont{Chirurgiche Avanzate}}
\end{tabular}
\end{minipage}
}
% Infos
\title{Tesi}
\author{Tu}
\date{April 2024}
% Inizio
% -------------------------
\begin{document}
\begin{titlepage}
\thispagestyle{fancy}
\vspace*{10em}
\fontsize{14pt}{14pt}\selectfont
\textit{Corso di Laurea Magistrale in}
\fontsize{18pt}{18pt}\selectfont
\textbf{Medicina e Chirurgia - Sede di Caserta}
\vspace*{5em}
{
\sffamily
\fontsize{14pt}{14pt}
\textbf{Tesi di Laurea Sperimentale/Compilativa in (indicare Materia e SSD)}
\vspace*{0.25em}
\fontsize{23pt}{23pt}
\text{Titolo della tesi}
\fontsize{14}{14}
\selectfont{Sottotitolo}
}
\vspace*{15em}
\begin{table}[hbt!]
\centering
\begin{tabular}{p{0.25\textwidth}p{0.2\textwidth}p{0.21\textwidth}p{0.2\textwidth}}
\makecell[l]{Candidato \\ \fontsize{13pt}{13pt}\selectfont\textit{Tizio Caio} \\ Matr. A2300XXX} & ~ & \makecell[l]{Relatore \\ \fontsize{13pt}{13pt}\selectfont\textit{Prof.} \\ \fontsize{13pt}{13pt}\selectfont\textit{Tizio Caio}} & A.A. 2024/2025
\end{tabular}
\end{table}
\end{titlepage}
\end{document}