如何透過 fancyhdr 在標題中設定圖像?

如何透過 fancyhdr 在標題中設定圖像?

我對 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}

結果

相關內容