Cách trang trí Header và Footer đẹp trong LaTeX

Cách soạn câu hỏi dạng điền khuyết trong LaTeX

Sau đây  VniTeach sẽ giới thiệu đến các bạn cách trang trí Header và Footer đẹp trong LaTeX.

% Trang trí Header và Footer đẹp trong LaTeX

% Cài đặt văn bản
\documentclass[a4paper,12pt,openany]{book}
\usepackage[utf8]{vietnam}
\usepackage{fontspec,tikz,changepage,fancyhdr,lipsum}

% Cài đặt các lề và màu sắc
\def\tren{1.5}\def\duoi{1.5}\def\trai{2.4}\def\phai{1.4} % Cài đặt các lề
\definecolor{myblue}{RGB}{0,0,255} % Định nghĩa màu myblue
\def\topset{1} % Định nghĩa topset
\def\botset{1} % Định nghĩa botset

% Định nghĩa lệnh vẽ header
\newcommand{\myfancyhead}{%
	\begin{tikzpicture}[remember picture,overlay]
		% Kiểm tra trang lẻ/chẵn
		\checkoddpage
		\ifoddpage % Nếu là trang lẻ
		\def\kctrai{\trai} \def\kcphai{\phai}
		\pgfmathsetmacro{\kctren}{-\tren+0.5*\topset} 
		\path ([yshift=\kctren cm]current page.north west) coordinate (AA)
		++(\paperwidth,0)coordinate (BB); 
		% Vẽ header bên phải
		\foreach \ii/\mau in {1.35/myblue!30,1/myblue!50,0.5/myblue!70,-0.1/myblue!80}{
			\fill[\mau,draw=white,line width=2pt] ([xshift=3pt,yshift=-2pt]BB)--++(-\kcphai cm-\ii cm-3pt,0)
			--++(-0.3,0.5cm+1pt)--++(\kcphai cm +\ii cm+3pt+0.3 cm,0)--cycle;
		}
		% Hiển thị chương/trang bên phải
		\node[anchor=south east,text=myblue,inner sep=0pt] at ([xshift=-\kcphai cm-1.35cm-8pt]BB){
			\fontfamily{qag}\fontsize{8pt}{12pt}\selectfont\nouppercase{\rightmark}
		};
		% Vẽ đường kẻ ngang
		\draw[myblue, line width=1pt] ([yshift=0.5cm]AA)--([yshift=0.5cm]BB);
		\else % Nếu là trang chẵn
		\def\kctrai{\phai} \def\kcphai{\trai}
		\pgfmathsetmacro{\kctren}{-\tren+0.5*\topset} 
		\path ([yshift=\kctren cm]current page.north west) coordinate (AA)
		++(\paperwidth,0)coordinate (BB); 
		% Vẽ header bên trái
		\foreach \ii/\mau in {1.35/myblue!30,1/myblue!50,0.5/myblue!70,-0.1/myblue!80}{
			\fill[\mau,draw=white,line width=2pt] ([xshift=-3pt,yshift=-2pt]AA)--++(\kctrai cm+\ii cm+3pt,0)--++(0.3,0.5cm+1pt)--++(-\kctrai cm -\ii cm-3pt-0.3cm,0)--cycle;
		}
		% Hiển thị chương/trang bên trái
		\node[anchor=south west,text=myblue,inner sep=0pt] at ([xshift=\kctrai cm+1.35cm+8pt]AA){
			\fontfamily{qag}\fontsize{8pt}{12pt}\selectfont\nouppercase{\leftmark}
		};
		% Vẽ đường kẻ ngang
		\draw[myblue, line width=1pt] ([yshift=0.5cm]AA)--([yshift=0.5cm]BB);
		\fi
	\end{tikzpicture}%
}

% Định nghĩa lệnh vẽ footer
\newcommand{\myfancyfoot}{%
	\begin{tikzpicture}[remember picture,overlay]
		\checkoddpage
		\ifoddpage % Nếu là trang lẻ
		\def\kctrai{\trai} \def\kcphai{\phai}
		\pgfmathsetmacro{\kcduoi}{\duoi-0.75*\botset} 
		\path ([yshift=\kcduoi cm,xshift=\kctrai cm]current page.south west) coordinate (AA)
		++(\textwidth,0)coordinate (BB); 
		% Vẽ footer bên trái
		\fill[right color=myblue, left color=myblue!10!white, rounded corners=0mm] ([xshift=3*\phai cm,yshift=0.07 cm]BB) rectangle +(-3.3*\phai cm,-0.6cm);
		% Hiển thị số trang bên trái
		\node[anchor=east,text=black,inner sep=0pt,xshift=0.47cm] at ([yshift=-2.3mm,xshift=2mm]BB) {
			\fontfamily{put}\bfseries\thepage
		};
		% Hiển thị tiêu đề bên trái
		\node[anchor=east,text=myblue,inner sep=0pt] (tt) at ([yshift=-2.5mm,xshift=-7mm]BB){
			\fontfamily{qag}\fontsize{9pt}{1pt}\selectfont TOÁN 12 -- CHƯƠNG TRÌNH MỚI
		};
		% Vẽ đường kẻ ngang
		\draw[myblue,opacity=0.5,line width=1pt] ([xshift=-3pt]tt.west) --++(-\textwidth,0);
		% Vẽ dấu chấm bên trái
		\foreach \vt/\mau in {0/myblue!60,5/myblue!40,10/myblue!20,15/myblue!10,20/myblue!5}{
			\fill[fill=\mau] ([xshift=-\kctrai cm +\vt mm]AA) rectangle +(3.5mm,-5mm);
		}
		\else % Nếu là trang chẵn
		\def\kctrai{\phai} \def\kcphai{\trai}
		\pgfmathsetmacro{\kcduoi}{\duoi-0.75*\botset} 
		\path ([yshift=\kcduoi cm,xshift=\kctrai cm]current page.south west) coordinate (AA)
		++(\textwidth,0)coordinate (BB); 
		% Vẽ footer bên phải
		\fill[left color=myblue, right color=myblue!10!white, rounded corners=0mm] ([xshift=0.2*\trai cm,yshift=0.07 cm]AA) rectangle +(-3*\trai cm,-0.6cm);
		% Hiển thị số trang bên phải
		\node[anchor=west,text=black,inner sep=0pt,xshift=-1.7cm] at ([yshift=-2.3mm,xshift=12mm]AA) {
			\fontfamily{put}\bfseries\thepage
		};
		% Hiển thị tiêu đề bên phải
		\node[anchor=west,text=myblue,inner sep=0pt] (tentg) at ([yshift=-2.5mm,xshift=8mm]AA){
			\fontfamily{qag}\fontsize{9pt}{1pt}\selectfont TOÁN 12 -- CHƯƠNG TRÌNH MỚI
		}; 
		% Vẽ đường kẻ ngang
		\draw[myblue,opacity=0.5,line width=1pt] ([xshift=3pt]tentg.east) --++(\textwidth,0);
		% Vẽ dấu chấm bên phải
		\foreach \vt/\mau in {0/myblue!60,-5/myblue!40,-10/myblue!20,-15/myblue!10,-20/myblue!5}{
			\fill[fill=\mau] ([xshift=\kcphai cm +\vt mm]BB) rectangle +(-3.5mm,-5mm);
		}
		\fi
	\end{tikzpicture}%
}

% Chỉ định page style
\pagestyle{fancy}
\fancyhead[LO,RE]{\myfancyhead} % Header cho trang lẻ và trang chẵn
\fancyfoot[LO,RE]{\myfancyfoot} % Footer cho trang lẻ và trang chẵn

\begin{document}
	% Văn bản mẫu
	\lipsum[1-10]
\end{document}

Chúc bạn thành công!

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *