在 LaTeX 中复制 Word 报告模板

在 LaTeX 中复制 Word 报告模板

我正在尝试用 LaTeX 重现一个 Word 报告模板,以加快我的报告撰写速度。我有一些基本的 LaTeX 技能,但在制作如图所示的蓝色页面边框时遇到了麻烦。我也不知道如何创建带有页面边框和蓝色框内标题的页眉信息。我假设可以使用 TikZ 包来绘制页面边框和页眉信息,fancyheader但如何一起使用这些包让我感到困惑。

我已附上要复制的基本 Word 文档的图片。请注意,显示的所有信息都将在每一页上重复。

任何帮助和指导都将不胜感激。

word模板http://static.dyp.im/WPtl9sR7Yk/e040cc378436b6fe4a32f9960fd0112e.PNG

答案1

这是通过结合使用everypage包和 TikZ 实现的。

输出顶部

输出底部

产出利差

要构建,请运行

pdflatex -recorder <file>
pdflatex <file>

第一次运行-recorder是为了生成包所需的文件currfile(使左下角自动化)。第二次运行是为了解决 TikZ 问题并解决右下角使用的标签。(第一次运行后可以看到一些奇怪的行为。)

使用方法如下:

\documentclass{wordreport}
\usepackage{mwe}

\address{123 Main St.}
        {City, State}
        {ZIP}
\phone{(777) 777-7777}
\fax{(777) 777-7777}
\webaddress{tex.stackexchange.com}

\title{TEST REPORT}
\preparedfor{--prepared--}
\poreference{--PO--}
\projectnumber{--project-number--}
\testreportnumber{--test-report-number--}
\logoimage{example-image-a}

\begin{document}
\lipsum[1-20]
\end{document}

类文件

由于这是一个 Word 模板,因此为其创建一个文档类是合适的:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{wordreport}[2014/01/01 A domain-specific, Word-like report template]

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{report}}
\ProcessOptions*
\LoadClass{report}

\RequirePackage{tikz}
\usetikzlibrary{calc}
\RequirePackage[abspath]{currfile}
\RequirePackage{lastpage}
\RequirePackage{everypage}
\RequirePackage{marvosym}

\def\address#1#2#3{%
  \gdef\@addressA{#1}%
  \gdef\@addressB{#2}%
  \gdef\@addressC{#3}}
\def\phone#1{%
  \gdef\@phone{#1}}
\def\fax#1{%
  \gdef\@fax{#1}}
\def\webaddress#1{%
  \gdef\@webaddress{#1}}

\def\preparedfor#1{%
  \gdef\@prepared@for{#1}}
\def\poreference#1{%
  \gdef\@po@reference{#1}}
\def\projectnumber#1{%
  \gdef\@project@number{#1}}
\def\testreportnumber#1{%
  \gdef\@test@report@number{#1}}
\def\logoimage#1{%
  \gdef\@logoimage{#1}}

\def\phonesymbol#1{%
  \gdef\@symbol@phone{#1}}
\def\faxsymbol#1{%
  \gdef\@symbol@fax{#1}}
\def\webaddresssymbol#1{%
  \gdef\@symbol@webaddress{#1}}

\def\@symbol@phone{\Telefon}
\def\@symbol@fax{\Faxmachine}
\def\@symbol@webaddress{\Lightning}

\tikzset{
  report blue/.style={
    color=blue!50!white,
  },
  report gray/.style={
    color=gray,
  },
  report frame/.style={
    thick,
    report blue,
  },
}

\AddEverypageHook{%
  \begin{tikzpicture}[remember picture, overlay]
      \coordinate (top left)     at ($ (current page.north west) + (1cm,  -1cm) $);
      \coordinate (top right)    at ($ (current page.north east) + (-1cm, -1cm) $);
      \coordinate (bottom left)  at ($ (current page.south west) + (1cm,  1cm) $);
      \coordinate (bottom right) at ($ (current page.south east) + (-1cm, 1cm) $);
%      
      \coordinate (frame top left)     at ($ (top left)  - (0, 2.5cm) $);
      \coordinate (frame top right)    at ($ (top right) - (0, 2.5cm) $);
      \coordinate (frame bottom left)  at ($ (bottom left)  + (0, .5cm)$);
      \coordinate (frame bottom right) at ($ (bottom right) + (0, .5cm)$);
%
      \coordinate (frame title mid left)  at ($ (frame top left)  + (1cm,  0) $);
      \coordinate (frame title mid right) at ($ (frame top right) + (-1cm, 0) $);
      \coordinate (frame title top left)  at ($ (frame title mid left) + (0, 3mm) $);
      \coordinate (frame title top right) at ($ (frame title mid right) + (0, 3mm) $);
      \coordinate (frame title bottom left)  at ($ (frame title mid left) - (0, 10mm) $);
      \coordinate (frame title bottom right) at ($ (frame title mid right) - (0, 10mm) $);
%
      \node [opacity=0.5] at (top left)  [below right]
      {%
        \includegraphics[width=2cm]{\@logoimage}%
      };
      \node [report blue] at ($ (top left) + (0cm, -1.9cm) $) [right]
      {%
        \sffamily TEST REPORT%
      };
      \node [report blue] at ($ (top right) + (3mm, -2mm) $) [below left]
      {%
        \sffamily
        \footnotesize
        \begin{tabular}{lcl}
          Address Information. &                               \\[.5ex]
          \@addressA           & \@symbol@phone      & \@phone \\  %marvosym
          \@addressB           & \@symbol@fax        & \@fax   \\ %marvosym
          \@addressC           & \@symbol@webaddress & \@webaddress
        \end{tabular}
      };
      \node [opacity=0.5, report blue] at ($ (frame bottom left) - (3mm, 0) $) [below right]
      {%
        \begin{tabular}{l}
          \sffamily
          \footnotesize
          COMPANY CONFIDENTIAL \\[-1ex]
          \scriptsize\ttfamily
          \currfileabspath
        \end{tabular}
      };
      \node [opacity=0.5, report blue] at ($ (frame bottom right) + (2mm - 2pt, 0) $) [below left]
      {%
        \sffamily
        \footnotesize
        Page \thepage\ of \pageref{LastPage}
      };
      \node [report gray] at ($ (frame top right)!.5!(frame top left) $) [below]
      {%
        \sffamily
        \@title
      };
      \node [report gray] at ($ (frame title bottom left) - (3mm, 0) $) [below right]
      {%
        \sffamily
        \footnotesize
        \begin{tabular}{rl}
          Prepared for: & \@prepared@for \\
          PO Reference: & \@po@reference
        \end{tabular}
      };
      \node [report gray] at ($ (frame title bottom right) + (3mm, 0) $) [below left]
      {%
        \sffamily
        \footnotesize
        \begin{tabular}{rr}
          Project Number: & \@project@number \\
          Test Report Number: & \@test@report@number
        \end{tabular}
      };
%
      \draw[report frame]
        (frame bottom left) --
        (frame bottom right);
      \draw[report frame]
        ($ (frame bottom left) + (0cm, 1mm) $) --
        (frame top left) --
        (frame title mid left);
      \draw[report frame]
        ($ (frame bottom right) + (0cm, 1mm) $) --
        (frame top right) --
        (frame title mid right);
      \draw[report frame]
        (frame title top left) rectangle (frame title bottom right);
    \end{tikzpicture}
  }

\pagestyle{empty}

\RequirePackage[top=5.5cm,
               left=2cm,
              right=2cm,
             bottom=2cm]{geometry}

由于对该问题的连续编辑将 CW 它,请参阅要旨以便日后进行任何修订。

相关内容