tikz 및 fancyhdr을 사용하여 연속 페이지로 레터헤드 모방

tikz 및 fancyhdr을 사용하여 연속 페이지로 레터헤드 모방

연속 페이지가 포함된 레터헤드를 모방하려고 합니다. 레터헤드 형식은 첫 페이지에 컬러 배너를 배치하고 오른쪽에 로고를 왼쪽에 부서명을 기재하는 형식입니다. 또한 첫 페이지 하단에는 부서 주소가 나와 있습니다. 이들 모두는 절대적으로 위치해야 합니다. 계속되는 페이지에는 같은 위치에 로고가 있지만 다른 것은 없습니다.

나는 무지해서 페이지 좌표를 사용하여 tikz로 절대 위치 지정을 수행할 것이라고 생각했습니다. 이것은 첫 번째 페이지에서는 작동하지만 연속 페이지에서는 작동하지 않는 것 같습니다. 즉, 연속 페이지에는 로고와 로고만 포함되어야 하지만 아무것도 포함되지 않습니다. 지금까지 나는 질문에 대한 답변을 찾을 수 없었으며 fancyhdr의 어리석은 실수로 길을 잃었으며 아마도 잘못된 부팅 방법을 사용하고 있다고 확신합니다.

다음은 현재 출력의 예입니다. 두 번째 페이지와 모든 후속 페이지에는 첫 번째 페이지와 정확히 동일한 위치에 데모 이미지가 있어야 합니다.

문제를 보여주는 출력 이미지

여기 클래스 파일이 있습니다

% class file MWE
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mweletter}

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}

\ProcessOptions

\RequirePackage[demo]{graphicx}
\LoadClass[a4paper]{letter}
\RequirePackage[left=2.5cm,showframe]{geometry}
\RequirePackage{fancyhdr}
\RequirePackage{tikz}
%\RequirePackage{fontspec}
\usetikzlibrary{calc}

\newsavebox{\addressbox}
\savebox{\addressbox}{
  \sffamily\fontsize{8}{10}\selectfont
  \textcolor{blue}{\begin{minipage}{7cm}
      Block A Level 4, Simpson Street, Springfield USA  \\%
    Tel: (+1) 617 123 4567 \\
  \end{minipage}}
}

\renewcommand{\headrulewidth}{0pt}%
\renewcommand{\footrulewidth}{0pt}%

\pagestyle{plain}
\AtBeginDocument{\thispagestyle{firstpage}}

\fancypagestyle{firstpage}{%
  \fancyhf{}%
  \begin{tikzpicture}[overlay, remember picture]
    \fill [anchor=north west,inner sep=0pt,orange]
      (current page.north west)  rectangle ($(current page.north east) + (0,-3cm)$);
    \node[anchor=north east,inner sep=0pt] at ($(current page.north east) + (-1cm,-0.5cm)$)
      {\includegraphics[height = 1.6cm]{demo}};
    \node[anchor=north west,inner sep=0pt] at
     ($(current page.north west) + (2.5cm,-0.5cm)$) {
      \sffamily\fontsize{8}{12} Department
      of Excellent Science };
    \node[anchor=south west, inner sep=0pt] at
    ($(current page.south west) + (2.5cm,1.5cm)$) {\usebox{\addressbox}};
  \end{tikzpicture}
}

\fancypagestyle{plain}{%
  \fancyhf{}%
  \begin{tikzpicture}[overlay, remember picture]
    \node[anchor=north east,inner sep=0pt]
    at ($(current page.north east) + (-1cm,-0.5cm)$)
    {\includegraphics[height = 1.6cm]{demo}};
  \end{tikzpicture}
}

그리고 이를 실행할 라텍스 파일도 있습니다.

\documentclass[12pt]{mweletter}
\usepackage{blindtext}
\signature{%
  Johnathan "John" I.Q. Neidelbaum Frink, Jr., B.Sc., Ph.D. M.R.S.C. \\ 
  The Principal Professor \\
  Springfield Heights Institute of Technology \\
  Springfield, America
}
\date{\today}
\begin{document}
\begin{letter}{Prof Tan\\
    Beijing Da Xue}
\opening{Dear Prof Tan,}
\Blindtext[5]
\closing{Yours sincerely,}
\encl{mweletter.cls}
\ps{Please see the enclosed file.}
\cc{Lisa Simpson}
\end{letter}
\end{document}

답변1

fancyhdrmarmot의 의견을 통해 애초에 사용하는 것이 얼마나 어리석은 것인지 깨닫게 되었습니다 . 나는 전혀 몰랐습니다 eso-pic. 이는 단순히 페이지에 요소를 배치하고 첫 번째 페이지를 다르게 처리합니다.

% mweletter.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{mweletter}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{letter}}
\ProcessOptions
\RequirePackage[demo]{graphicx}
\LoadClass[a4paper]{letter}
\RequirePackage[left=2.5cm,showframe]{geometry}
\RequirePackage{tikz}
\RequirePackage{eso-pic}
\usetikzlibrary{calc}

\AddToShipoutPicture{
  \begin{tikzpicture}[overlay, remember picture]
    \ifnum\value{page}=1 
    \fill [anchor=north west,inner sep=0pt,orange]
    (current page.north west)  rectangle ($(current page.north east) + (0,-3cm)$);
    \node[anchor=north west,inner sep=0pt] at
     ($(current page.north west) + (2.5cm,-0.5cm)$) {
      \sffamily\fontsize{8}{12} Department
      of Excellent Science };
    \node[anchor=south west, inner sep=0pt] at
    ($(current page.south west) + (2.5cm,1.5cm)$) {
      \sffamily\fontsize{8}{10}\selectfont
      \textcolor{blue}{
        \begin{minipage}{7cm}
          Block A Level 4, Simpson Street, Springfield USA  \\%
          Tel: (+1) 617 123 4567 \\
        \end{minipage}}};
    \fi
    \node[anchor=north east,inner sep=0pt] at ($(current page.north east) + (-1cm,-0.5cm)$)
    {\includegraphics[height = 1.6cm]{demo}};
  \end{tikzpicture}
}

그리고 여기에 입력이 있습니다.

\documentclass[12pt]{mweletter}
\usepackage{blindtext}
\signature{%
  Johnathan "John" I.Q. Neidelbaum Frink, Jr., B.Sc., Ph.D. M.R.S.C. \\ 
  The Principal Professor \\
  Springfield Heights Institute of Technology \\
  Springfield, America
}
\date{\today}
\begin{document}
\begin{letter}{Prof Tan\\
    Beijing Da Xue}
\opening{Dear Prof Tan,}
\Blindtext[4]
\closing{Yours sincerely,}
\encl{mweletter.cls}
\ps{Please see the enclosed file.}
\cc{Lisa Simpson}
\end{letter}
\end{document}

주다

올바른 2up

관련 정보