我想创建一个具有以下结构的文档
标头
姓名、出生日期、地址<-------- 这将由不懂 LaTex 的人(在文档编写之前)编写,并将在每篇论文上重复。
内容 ...
页脚
这可能吗 ?
答案1
如果没有 MWE,很难猜测您正在尝试做什么...希望这是您想要的。
在\AddToShipoutPicture
eso-pic
包中我们在文档中创建一个“第二个标题”,用于写入所需的信息。
\documentclass{article}
\usepackage{eso-pic}
\usepackage{fancyhdr}
\usepackage{blindtext} % just for the example
\usepackage[headsep=2cm]{geometry}
\AddToShipoutPicture{%
\AtTextUpperLeft{%
\makebox(420,45)[lt]{%
\footnotesize%
\textbf{Author: }\myauthor%
\hspace*{.5cm}%
\textbf{Date of birth: }\mydate%
\hspace*{.5cm}%
\textbf{Address: }\myaddress%
}}}
\pagestyle{fancy}
\newcommand{\myauthor}{}
\newcommand{\mydate}{}
\newcommand{\myaddress}{}
\begin{document}
\blinddocument % just for the example
\end{document}
现在“人”只需填写字段\myauthor
,\myauthor
和\myauthor
。
例如,如果您设置(对不起,约翰......)
\newcommand{\myauthor}{John Wayne}
\newcommand{\mydate}{May 26, 1907}
\newcommand{\myaddress}{Winterset, Iowa}
你会得到
答案2
按照References
以下方法,有多种方法可以在每个页面上放置内容。因此,本文旨在介绍我建议如何让不懂 LaTeX 的用户提供所需的信息,即通过 CSV 文件。在 MWE 中,该文件的命名AuthorInfo.csv
和包含的信息如下:
Mr. Vaibhav, May 4, 1977, 1138 TeX-SE Way, Cupertino, CA, USA
这是我能想到的提供数据的最简单的方法,但逗号很重要,因为它们提供了分隔。如果您更喜欢可以轻松容纳的此文件的替代格式,那么以上就是我想到的。
如果将 MWE 中的序言移动到文件中.sty
,则该文档:
\documentclass{book}
\usepacakge{MyPreamble}% <--- MyPreamble.sty needs to contain the preamble in the MWE below
\begin{document}
\chapter{First Chapter}
\lipsum[1-12]
\end{document}
使用AuthorInfo.csv
如上所述的文件生成:
笔记:
- 包裹
filecontents
用于设置要为此测试用例读取的文件。实际用例中不需要它。 - 如果你希望看到特定设置的页边距,请取消注释
\usepackage{showframe}
在 MWE 中。
参考:
放置文本/图像的方法每个页面涵盖:
代码:
%% Use filecontents to create the AuthorInfo.tex file. IN real use case,
%% this file would be created by the non-LaTeX davy users. Note that the
%% commas here are important as they are used to parse the data.
\newcommand*{\AuthorInfoFileName}{AuthorInfo.csv}
\begin{filecontents*}{\AuthorInfoFileName}
Mr. Vaibhav, May 4, 1977, 1138 TeX-SE Way, Cupertino, CA, USA
\end{filecontents*}
\documentclass{book}
\usepackage[all]{background}
\usetikzlibrary{calc}
\usepackage{datatool}
\usepackage{fancyhdr}
\usepackage{lipsum}
%\usepackage{showframe}
\usepackage{layout}
\usepackage{changepage}
\strictpagecheck
\newcommand*{\HeaderIndent}{0.0cm}%
\newcommand*{\HeaderOffsetY}{0.40cm}%
\newcommand*{\HeaderXLocation}{\dimexpr1.0in+\hoffset+\HeaderIndent\relax}%
\newcommand*{\HeaderYLocation}{\dimexpr1.0in+\voffset+\topmargin+\headheight+\HeaderOffsetY\relax}%
\newcommand{\MyTikzLogo}{% For a logo drawn with TikZ
\begin{tikzpicture}[remember picture,overlay,draw=black,ultra thick]
\checkoddpage
\ifoddpage
\coordinate (Title Location) at
($(current page.north west)+(\HeaderXLocation,-\HeaderYLocation)+(\oddsidemargin,0)$);
\else
\coordinate (Title Location) at
($(current page.north west)+(\dimexpr\HeaderXLocation,-\HeaderYLocation)+(\evensidemargin,0)$);
\fi
\node [draw=none, fill=none, anchor=south west, text=black, font=\bfseries]
at (Title Location) {\HeaderTitle};
\end{tikzpicture}%
}
\newcommand*{\AuthorName}{unkown}%
\newcommand*{\AuthorBirthday}{XX-XX-XX}%
\newcommand*{\AuthorAddress}{123 Main St., Anywhere, USA}%
\newcommand*{\HeaderTitle}{%
\scriptsize\normalfont%
\textbf{Name}: \AuthorName%
~\textbf{Birthday:} \AuthorBirthday%
~\textbf{Address:} \AuthorAddress%
}
\newcommand*{\GetValueOfColumnAtRowOfMyDb}[3]{%
% #1 = csname of where to store the result
% #2 = key for column
% #3 = row number
\DTLgetvalue{#1}{myDB}{#3}{\dtlcolumnindex{myDB}{#2}}%
}%
\newcommand*{\LoadAuthorInfo}{%
\DTLloaddb[noheader,
keys={%
AuthorName,%
AuthorBDayMonthDate,AuthorBDayYear,%
AuthorStreet,AuthorCity,AuthorState,AuthorCountry%
}%
]{myDB}{\AuthorInfoFileName}%
%\DTLdisplaydb{myDB}% Helps with Debugging
\GetValueOfColumnAtRowOfMyDb{\AuthorName}{AuthorName}{1}%
\GetValueOfColumnAtRowOfMyDb{\AuthorBDayMonthDate}{AuthorBDayMonthDate}{1}%
\GetValueOfColumnAtRowOfMyDb{\AuthorBDayYear}{AuthorBDayYear}{1}%
\GetValueOfColumnAtRowOfMyDb{\AuthorStreet}{AuthorStreet}{1}%
\GetValueOfColumnAtRowOfMyDb{\AuthorCity}{AuthorCity}{1}%
\GetValueOfColumnAtRowOfMyDb{\AuthorState}{AuthorState}{1}%
\GetValueOfColumnAtRowOfMyDb{\AuthorCountry}{AuthorCountry}{1}%
% -------
\renewcommand{\AuthorBirthday}{\AuthorBDayMonthDate, \AuthorBDayYear}%
\renewcommand{\AuthorAddress}{\AuthorStreet, \AuthorCity, \AuthorState, \AuthorCountry}%
}
\AtBeginDocument{\LoadAuthorInfo}
\SetBgContents{\MyTikzLogo}% Set tikz picture
\SetBgPosition{current page.north west}% Select location
\SetBgOpacity{1.0}% Select opacity
\SetBgAngle{0.0}% Select rotation of logo
\SetBgScale{1.0}% Select scale factor of logo
\pagestyle{fancy}
\begin{document}%\layout% <-- comment out to see page layout
\chapter{First Chapter}
\lipsum[1-12]
\end{document}
答案3
我想下面的内容应该或多或少能满足你的要求。仍然需要大量完善。我很快会添加一种新的、更友好的方法。
\documentclass[headinclude=true]{scrartcl}
\usepackage{blindtext} % just for the example
\newkomafont{templatefont}{\bfseries\small}
\newkomafont{patientfont}{\small}
\usepackage[automark]{scrlayer-scrpage}
\setlength{\headheight}{30pt}
\clearpairofpagestyles
\makeatletter
\def\@address{}
\def\@name{}
\def\@birthdate{}
\newcommand{\address}[1]{\gdef\@address{#1}}
\newcommand{\name}[1]{\gdef\@name{#1}}
\newcommand{\birthdate}[1]{\gdef\@birthdate{#1}}
\ohead{\leftmark\\{\usekomafont{templatefont}Address:}\space\usekomafont{patientfont}\@address}
\ihead{\\{\usekomafont{templatefont}Name:}\space\usekomafont{patientfont}\@name}
\chead{\\{\usekomafont{templatefont}Birthdate:}\space\usekomafont{patientfont}\@birthdate}
\makeatother
\newcommand{\newpatient}{\clearpage}
\begin{document}
\name{Some Dude}
\birthdate{March 1939}
\address{Some street}
\blinddocument
\newpatient
\name{vaibhav}
\birthdate{22.11.1966}
\address{Street, House 18}
\blinddocument
\end{document}