创建复杂模板

创建复杂模板

我想创建一个复杂的文档模板作为文档类。

我应该能够定义我的text字段(例如,\documentNumber\projectTitle。我的类应该足够灵活,以适应横向页面。XeTeX最好。

这是文档模板的草图:

布局草图

我唯一的想法就是在每个页面上创建一个 tikzpicture,如我的其他问题所述。我得到了关于使用 等的建议everypageeveryshi我希望得到更具体的答案。最欢迎代码片段或只是概述的编码概念。

答案1

根据马修的预测,我将在 ConTeXt 中这样布局。顶部的表格可以设置为标题。左边距的标注可以使用图层设置。我们可以通过仔细添加frame=onframe=off添加到不同的元素来添加框架(边框)。剩下的只是设置右边距等的问题。

\setuplayout  
  [topspace=1\lineheight,
   top=1\lineheight,
   topdistance=0cm,
   header=1.25in,
   headerdistance=0cm,
   height=fit,
   footerdistance=0cm,
   footer=0.5in,
   bottomspace=0.25\lineheight,
   bottom=0.25\lineheight,
   bottomdistance=0cm,
   backspace=0.75in,
   width=fit,
   cutspace=0.125in,
 ]

\setupbackgrounds[text][text][frame=on]

% Header
\setuppagenumbering[location=]
\setupheadertexts[\setups{header}]

% Left margin
\definelayer [leftlayer] 
             [width=\paperwidth,
              height=\paperheight,
              x=0cm,
              y=1cm]

\defineframed[margincallout]
             [height=\dimexpr\layoutparameter{backspace}\relax,                        
              width=\dimexpr(\textheight+\layoutparameter{header})/2\relax,
              align={middle,middle},
              foregroundstyle=\tfc,
              frame=off]

\setlayer        [leftlayer] [preset=leftbottom] 
                 {\rotate{\margincallout[rightframe=on]{Rotated text callout 1} }}

\setlayer        [leftlayer] [preset=lefttop,y=2.5mm]
                 {\rotate{\margincallout {Rotated text callout 2} }}

\setupbackgrounds[page][background=leftlayer]

% Actual content
\startsetups header
  \setupTABLE[each][each][height=\dimexpr\layoutparameter{header}/4\relax,
                          width=0.25\textwidth,
                          align={middle,middle},
                          frame=on]
  \bTABLE
    \bTR
      \bTD[nr=3]      \fakewords {5} {10} \eTD
      \bTD[nr=3,nc=2] \fakewords {5} {10} \eTD
      \bTD \fakewords{1}{3}               \eTD
    \eTR
    \bTR
       \bTD \fakewords{1}{3} \eTD
    \eTR
    \bTR
      \bTD \fakewords{1}{3} \eTD
    \eTR
    \bTR
      \bTD \fakewords{1}{2} \eTD
      \bTD \fakewords{1}{2} \eTD
      \bTD \fakewords{1}{2} \eTD
      \bTD \fakewords{1}{2} \eTD
    \eTR
  \eTABLE
\stopsetups


% For dummy text
\usemodule[visual]
\starttext
Page Content
\stoptext

输出如下:在此处输入图片描述

答案2

您可以尝试textpos包或 TeX FAQ 页面上描述的一些其他解决方案“将内容放置在页面上的固定位置”

如果你习惯使用 TikZ 来做这种事情,不要害怕。是的,它有很多“开销”,但它确实有效。

虽然我对此了解甚少,但我听说 ConTeXt 在这方面做得很好。所以我们应该很快就会从他们的用户那里得到答案。

答案3

在您慷慨的帮助下,我终于解决了我的需求。我对整体的黑客行为不是很满意,但它解决了我的需求。希望它能对其他人有所帮助。

文档:

\documentclass[12pt,a4paper]{class}

\usepackage{lipsum}

\projecttitle{My project name}
\metadata{Metadata}
\metadataTwo{Metadata Two}
\metadataThree{Metadata Three}
\metadataFour{Metadata Four}
\metadataFive{Metadata Five}
\metadataSix{Metadata Six}

\begin{document}

\section{Lipsum}
\lipsum[1]
\section{Phasellus eu tellus}
\lipsum[1-12]
\end{document}

文档类别:

\ProvidesClass{class}
\LoadClass[12pt,a4paper]{article}

\newcommand{\projecttitle}[1]{\gdef\@projecttitle{#1}}
\newcommand{\metadata}[1]{\gdef\@metadata{#1}}
\newcommand{\metadataTwo}[1]{\gdef\@metadataTwo{#1}}
\newcommand{\metadataThree}[1]{\gdef\@metadataThree{#1}}
\newcommand{\metadataFour}[1]{\gdef\@metadataFour{#1}}
\newcommand{\metadataFive}[1]{\gdef\@metadataFive{#1}}
\newcommand{\metadataSix}[1]{\gdef\@metadataSix{#1}}

\usepackage{polyglossia}
\setmainlanguage{croatian}

\usepackage{fontspec}
\defaultfontfeatures{Mapping=tex-text}
\usepackage{xunicode}
\usepackage{xltxtra}
\setmainfont{Minion Pro}

\usepackage{geometry}
\geometry{%
    a4paper,%
    hmargin={3.5cm,2.5cm},%
    headheight=2cm,%
    headsep=1cm,%
    marginparwidth=1.1cm,%
    marginparsep=0.2cm%
}

\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage{lipsum}
\usepackage{graphicx}
\usepackage{microtype}
\usepackage{tikz}
\usetikzlibrary{calc}
\tikzstyle{content box}=[]

\usepackage{lastpage}

\def\logowidthratio{0.25}
\def\titlewidthratio{0.5}
\def\rightcolumnwidthratio{0.25}

\newlength\framewidth
\setlength{\framewidth}{\paperwidth-3cm}
\newlength\frameheight
\setlength{\frameheight}{\paperheight-2cm}

\newlength{\logowidth}
\setlength{\logowidth}{\logowidthratio\framewidth}

\newlength{\titlewidth}
\setlength{\titlewidth}{\titlewidthratio\framewidth}

\newlength{\logoandtitlewidth}
\setlength{\logoandtitlewidth}{\logowidth+\titlewidth}

\newlength{\rightcolumnswidth}
\setlength{\rightcolumnswidth}{\framewidth - \logoandtitlewidth}

\newlength{\padding}
\setlength{\padding}{6pt}

\lhead{}
\chead{}
\rhead{}
\lfoot{}
\cfoot{}
\rfoot{}
\renewcommand{\headrulewidth}{0.0pt}
\renewcommand{\footrulewidth}{0.0pt}


\AtBeginDocument{
    \newsavebox{\logobox}
    \sbox{\logobox}{
        \parbox{\logowidthratio\framewidth-2\padding}{
            \centering
            \rule{\logowidth-2\padding}{2cm}% graphic dummy
            }
        }

    \newsavebox{\titlebox}
    \sbox{\titlebox}{\parbox{\titlewidthratio\framewidth-2\padding}{
        \centering\large\textsc{Project name}\linebreak\textbf{\@projecttitle}}
        }

    \newsavebox{\metadatabox}
    \sbox{\metadatabox}{
        \parbox{\rightcolumnswidth-2\padding}{Metadata: \@metadata}
        }

    \newsavebox{\docnumbox}
    \sbox{\docnumbox}{
        \parbox{\rightcolumnswidth-2\padding}{Metadata: \@metadataTwo}
        }

    \newsavebox{\revisionbox}
    \sbox{\revisionbox}{
        \parbox{\rightcolumnswidth-2\padding}{Metadata: \@metadataThree}
        }

    \newsavebox{\contractnumbox}
    \sbox{\contractnumbox}{
        \parbox{\logowidth-2\padding}{Metadata: \@metadataFour}
        }

    \newsavebox{\projectnumbox}
    \sbox{\projectnumbox}{
        \parbox{0.5\titlewidth-2\padding}{Metadata: \@metadataFive}
        }

    \newsavebox{\bookbox}
    \sbox{\bookbox}{
        \parbox{0.5\titlewidth-2\padding}{Metadata: \@metadataSix}
        }

    \newsavebox{\pagenumbox}
    \sbox{\pagenumbox}{
        \parbox{\rightcolumnswidth-2\padding}{\hphantom{Page: 123 of 123}}
        }

    \newlength\logoheight
    \settototalheight\logoheight{\usebox{\logobox}}
    \addtolength{\logoheight}{2\padding}

    \newlength\titleheight
    \settototalheight\titleheight{\usebox{\titlebox}}
    \addtolength{\titleheight}{2\padding}

    \newlength\metadataheight
    \settototalheight\metadataheight{\usebox{\metadatabox}}

    \newlength\docnumheight
    \settototalheight\docnumheight{\usebox{\docnumbox}}

    \newlength\revisionheight
    \settototalheight\revisionheight{\usebox{\revisionbox}}

    \newlength\contractnumheight
    \settototalheight\contractnumheight{\usebox{\contractnumbox}}

    \newlength\projectnumheight
    \settototalheight\projectnumheight{\usebox{\projectnumbox}}

    \newlength\bookheight
    \settototalheight\bookheight{\usebox{\bookbox}}

    \newlength\pagenumheight
    \settototalheight\pagenumheight{\usebox{\pagenumbox}}

    \newlength\rightcolumnheight
    \pgfmathsetlength{\rightcolumnheight}{3*(max(\metadataheight,\docnumheight,\revisionheight)+2\padding}

    %45 points is sligtly more than 1,5 cm
    \newlength\headerfirstrowheight
    \pgfmathsetlength{\headerfirstrowheight}{max(\logoheight,\titleheight,\rightcolumnheight,45)}

    \newlength\headerheight
    \pgfmathsetlength{\headerheight}{\headerfirstrowheight + max(\contractnumheight,\projectnumheight,\bookheight,\pagenumheight)+12pt}

    \newgeometry{vmargin={\headerheight+1.5cm,1.5cm}}

    \chead{%
        \begin{tikzpicture}[remember picture, overlay, semithick, black, inner sep=0, outer sep=0]%
        %
        % OUTER FRAME AND COPYRIGHT DIVIDER
        % 
        %
        %Outer frame
        \node (frame) at ($(current page.center)+(0.5cm,0)$) [minimum width=\paperwidth-3cm,minimum height=\paperheight-2cm, draw] {};%
        %
        %Copyright divider
        \draw ($(current page.west)+(0.2cm,0)$) -- ($(current page.west)+(1.8cm,0)$);%
        %
        %
        % CONTENT BOXES
        %
        %
        %Revision information
        \node (revision information) at ($(frame.north west)!0.98!(frame.south west)$) [content box, xshift=-0.4cm, anchor=west, rotate=90] {\tiny Revision information text};%
        %
        %Copyright notice Croatian
        \node (copyright hrvatski) at ($(frame.north west)!0.75!(frame.south west)$) [content box, xshift=-1cm, rotate=90] {\parbox{0.25\frameheight}{\tiny\centering \lipsum[13]}};%
        %
        %Copyright notice English
        \node (copyright english) at ($(frame.north west)!0.25!(frame.south west)$) [content box, xshift=-1cm, rotate=90] {\parbox{0.25\frameheight}{\tiny\centering \lipsum[13]}};%
        %
        %Logo
        \node (logo) at (frame.north west) [content box,anchor=north west,outer sep=\padding] {\usebox{\logobox}};%
        %
        %Title
        \node (title) at ($(frame.north west)!\logowidthratio!(frame.north east)$) [content box,anchor=north west, outer sep=\padding] {\usebox{\titlebox}};%
        %
        %metadata metadata
        \node (metadata) at ($(frame.north west)!\logowidthratio+\titlewidthratio!(frame.north east)$) [content box,anchor=north west,outer sep=6pt] {\usebox{\metadatabox}};%
        %
        %Document number metadata
        \node (document number) at ($(frame.north west)!\logowidthratio+\titlewidthratio!(frame.north east)$) [content box,anchor=north west, yshift=-0.33\headerfirstrowheight,outer sep=6pt] {\usebox{\docnumbox}};%
        %
        %Revision metadata
        \node (revision) at ($(frame.north west)!\logowidthratio+\titlewidthratio!(frame.north east)$) [content box,anchor=north west, yshift=-0.66\headerfirstrowheight,outer sep=6pt] {\usebox{\revisionbox}};%
        %
        %Contract number metadata
        \node (contract number) at ($(frame.north west)-(0,\headerfirstrowheight)$) [content box,anchor=north west,outer sep=6pt] {\usebox{\contractnumbox}};%
        %
        %Project number metadata
        \node (project number) at ($(frame.north west)-(0,\headerfirstrowheight)$) [content box,anchor=north west,xshift=\logowidth,outer sep=6pt] {\usebox{\projectnumbox}};%
        %
        %Book number
        \node (book number) at ($(frame.north west)-(0,\headerfirstrowheight)$) [content box,anchor=north west,xshift=\logowidth+0.5\titlewidth,outer sep=6pt] {\usebox{\bookbox}};%
        %
        %Page number
        \node (page number) at ($(frame.north west)-(0,\headerfirstrowheight)$) [content box,anchor=north west,xshift=\logowidth+\titlewidth,outer sep=6pt] {Page: \thepage\ of \pageref{LastPage}};%
        %
        %
        % HEADER FAUX-TABLE GRID LINES
        %
        %
        %First header row horizontal bottom line
        \draw ($(frame.north west)-(0,\headerfirstrowheight)$) -- ($(frame.north east)-(0,\headerfirstrowheight)$);%
        %
        %Header horizontal bottom line
        \draw ($(frame.north west)-(0,\headerheight)$) -- ($(frame.north east)-(0,\headerheight)$);%
        %
        %Third header column, first row horizontal bottom line
        \draw ($($(frame.north west)!\logowidthratio+\titlewidthratio!(frame.north east)$)-(0,.33\headerfirstrowheight)$) -- ($(frame.north east)-(0,.33\headerfirstrowheight)$);%
        %
        %Third header column, second row horizontal bottom line
        \draw ($($(frame.north west)!\logowidthratio+\titlewidthratio!(frame.north east)$)-(0,.66\headerfirstrowheight)$) -- ($(frame.north east)-(0,.66\headerfirstrowheight)$);%
        %
        %First header column vertical right line
        \draw ($(frame.north west)!\logowidthratio!(frame.north east)$) -- ($(frame.north west)!\logowidthratio!(frame.north east) - (0,\headerheight)$);%
        %
        %Second header column vertical right line
        \draw ($(frame.north west)!\logowidthratio+\titlewidthratio!(frame.north east) - (0,\headerheight)$) -- ($(frame.north west)!\logowidthratio+\titlewidthratio!(frame.north east)$);%
        %
        %Second header row middle vertical
        \draw ($(frame.north west)+(\logowidth+0.5\titlewidth,-\headerfirstrowheight)$) -- ($(frame.north west)+(\logowidth+0.5\titlewidth,-\headerheight)$);%
        \end{tikzpicture}%
    }
}

相关内容