![fancyhdr 経由でヘッダーに画像を設定するにはどうすればいいですか?](https://rvso.com/image/475710/fancyhdr%20%E7%B5%8C%E7%94%B1%E3%81%A7%E3%83%98%E3%83%83%E3%83%80%E3%83%BC%E3%81%AB%E7%94%BB%E5%83%8F%E3%82%92%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B%E3%81%AB%E3%81%AF%E3%81%A9%E3%81%86%E3%81%99%E3%82%8C%E3%81%B0%E3%81%84%E3%81%84%E3%81%A7%E3%81%99%E3%81%8B%3F.png)
私は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}