5

I want to create a document which has the following structure

Header


Name, Date of birth, Address <-------- This will be written by people (before the document is compiled) who do not understand LaTex and will be repeated on every paper.


contents ...


footer

Is this possible ?

Adam
  • 4,684
Vaibhav
  • 6,625
  • 15
  • 49
  • 76
  • Why do you mean be "written"? Before or after compilation? – m0nhawk Nov 28 '13 at 10:33
  • before compilation – Vaibhav Nov 28 '13 at 10:35
  • 2
    Why can't the "Name, Date of birth, Address" just be part of the header? – StrongBad Nov 28 '13 at 10:42
  • Ah, I thought of it. But many times you do not want to mix say "letterheader" which contain your name with your client's name. Ego hurts! – Vaibhav Nov 28 '13 at 11:52
  • Can the text written below the line can be two line text?

    author DOB < ---- line 1 Address <- next line

    – Vaibhav Dec 07 '13 at 11:32
  • Can I use lyx to get similar format? Thanks for the earlier useful answer – Vaibhav Dec 07 '13 at 11:35
  • 2
    Please provide a MWE including \documentclass and the appropriate packages that sets up the problem. This will go a long way to eliminate the confusion here -- especially with how and exactly where you want the users to specify the input. – Peter Grill Oct 28 '14 at 17:27
  • 1
    If what you mean is that you want a Lyx solution, then you should make that clear when adding the MWE your questions so badly need. Given that few people here use Lyx, you are unlikely to get such a solution if you neither mention Lyx nor apply the Lyx tag in your. [Note that I know nothing about Lyx. But I am assuming from your comments that a (pdf/Xe/Lua)LaTeX solution is not suitable for use with Lyx else there would be no reason to request one as a follow up in comments *after* letting people put in all the hard work of solving what is anyway an underspecified problem from scratch. – cfr Oct 29 '14 at 02:22
  • 1
    Just a hint: You can edit the above question making changes easier for helpers to notice and much more important -> you can make the question and your problem description much more easy. – Johannes_B Oct 29 '14 at 14:17
  • As it stands, this question doesn't really have enough detail of what you've tried to be considered clear. Any answers will be speculation at best. I've refunded the bounty and closed. Please edit the question then flag it and I will reopen. Any edit should include key details which seem to be spread about in comments on the existing attempts to answer. – Joseph Wright Oct 30 '14 at 07:17

3 Answers3

12

Without a MWE it is difficult to guess what you are trying to do... Hope this is what you want.

With the help of \AddToShipoutPicture from the eso-pic package we create a "second header" in the document where to write the needed information.

\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} 

Now the "person" just has to fill in the fields \myauthor, \myauthor and \myauthor.

For example, if you set (sorry, John...)

\newcommand{\myauthor}{John Wayne}
\newcommand{\mydate}{May 26, 1907}
\newcommand{\myaddress}{Winterset, Iowa}

you will get

enter image description here

karlkoeller
  • 124,410
  • How can I edit the contents of main header? Can I use fancyhdr here to include left and right header (In this example, the header I want to change is reflected by 1 Heading on level 1 – Vaibhav Dec 03 '13 at 09:08
  • @user34083 Yes, you can do it with fancyhdr. Make a search over here and you'll find lots of examples. – karlkoeller Dec 03 '13 at 11:54
  • The \newcommand has to be used in preamble. This makes it difficult to use preamble as input file and using the code in lyx in preamble makes it difficult for a person who does not understand latex and moreover hates markup. Is there any simpler solution where we can offer a simpler solution to novice. Moreover if I write address in a single line, it is going to result in clutter. Kindly help – Vaibhav Dec 07 '13 at 18:19
  • Thanks for the excellent solution. But Can this be achieved in a better way? I mean when you just paste a block like a picture on the top of other page, the relationship between this block and the text on the page produces weired appearance. Can fancyhdr itself be tweeked to produce a header and sub-header? – Vaibhav Oct 27 '14 at 17:10
  • @Vaibhav To be honest, looking at the question, i really don't understand the question. I guess if you extend your question giving an explanation what you are trying to acieve might lead to better solutions. Maybe even asking a new question linking to this one. – Johannes_B Oct 28 '14 at 17:25
  • @johannes-b I use this template to prepare patient visit details. I want name and demographic details of the patient to be printed on every page. I don't want this information as a header as I use fancyhdr to create my letterhead. So I need this information to appear below the header line and to be repeated on everyone or at least on a new visit page which I start using clearpage . I think I am clear now. – Vaibhav Oct 28 '14 at 17:32
3

There are numerous ways to place content on each page as per the References below. So, this is intended to cover how I suggest that you get the non-LaTeX savvy users to provide the required info and that is via a CSV file. In the MWE the file is named AuthorInfo.csv and is contains the info as:

Mr. Vaibhav, May 4, 1977, 1138 TeX-SE Way, Cupertino, CA, USA

This is about the easiest way I can think of to providing the data, but the commas are important as they provide the sepration. If you prefer alternate form of this file that can easily be accomodated, so the above is just what I came up with.

If you move the preamble in the MWE to a .sty file, then the document:

\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}

with the AuthorInfo.csv file as described above produces:

enter image description here

Notes:

References:

Code:

%% 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}

Peter Grill
  • 223,288
  • Thanks but I am getting error You can't use `\dimexpr' in restricted horizontal mode. \dimexpr

    l.93 \lipsum[1-12]

    – Vaibhav Oct 29 '14 at 10:24
  • @Vaibhav: Are you seeing this problem with the MWE as I posted above, or in you actual use case. If it is the latter, please note that you have not provided any information as to the specifics of your document including even the \documentclass, so it is hard to determine the cause of the error. I'd suggest you compose a MWE including \documentclass and the appropriate packages that reproduces the problem you describe and add that to the question. – Peter Grill Oct 29 '14 at 18:45
2

I guess the following should more or less do what you desire. Still needs a lot of polishing. I will add a new, little bit more friendly approach soon.

\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} 
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • expand address to Some street, some city, some District and you will notice a problem – Vaibhav Oct 29 '14 at 10:22
  • 1
    You have been told several times now to prepare a working example showing your problem. Please do so if you want to have a solid solution. Right now, every answer relies on guesswork. – Johannes_B Oct 29 '14 at 14:01
  • btw, you can always use \address{Some street,\\ 09599 Free mountain,\\ neverland,\\ superdistrict}. If this information will alway be given, it should say so in the question. – Johannes_B Oct 29 '14 at 14:28
  • 2
    (+1) but I don't think this will be compatible with the requirement to retain the header configuration for letterhead which uses fancyhdr. This requirement is hidden in a comment on another user's answer to maximise the chances that you will fail to see it and so waste time and energy on a solution which @Vaibhav will then dismiss as unsuitable. (But induction presumably told you this already.) – cfr Oct 30 '14 at 01:02