# How can I construct a page layout with framed boxes?

For a report I'm writing, I have got an MS Word template for a page that needs to be included. The page looks like this (print screen from Word):

However, there are a few things that makes me not want to use this template in its current form, but rewrite it in LaTeX:

1. This page is in Word, while the rest of my report is in LaTeX. Hence the styles will be different, which includes fonts and line widths for example.
2. Word converts vector images stored in pdf format to low-resolved raster images when you include them (and yes it is still rasterized after you have printed it as a pdf file).

Anyway, enough of the arguing for using LaTeX already and to the question: How do I achieve this kind of layout using LaTeX? All I need to know for the moment is how to create these kind of boxes that exist right next to each other in this pattern, and how to get the text adjusted properly within the boxes.

Edit: It would be nice if the dimensions of the boxes were independent of the content inside of them. In that way the layout would stay the same for different people who used the same LaTeX template. My department at the university is maybe going to use it as an official alternative to the Word template.

• Could you edit your question (including the title) to focus more on the boxes than on this design as a whole? That would make it a much better fit for this site. – doncherry Apr 12 '13 at 20:25
• @doncherry: What more than the boxes is it I am asking about that you think is unnecessary for this question? – StrawberryFieldsForever Apr 13 '13 at 21:25
• I’m mostly thinking about the title and how users facing a similar challenge would find this question. A title like Constructing a page layout with framed boxes might be more helpful in that, but you might be able to come up with an even better title. – doncherry Apr 14 '13 at 16:26
• @doncherry: I've updated the title. – StrawberryFieldsForever Apr 19 '13 at 15:00

I do this in my reports. First you need the setup in your class or style file. In my case, it is our report class and it contains the following definitions for doing a govt SF-298 form:

\newenvironment{createSFtwoNINEeight}{
\clearpage
\begin{singlespace}
\begin{picture}(612,650)(70,82)
\includegraphics{SF298}
\footnotesize
\@SFitemONE{\@pubdate}
\@SFitemTWO{Final}
\@SFitemEIGHT{\@arlrptno}
\@SFitemTWELVE{\@distribution}
\def\SFitemSIXTEENaVALUE{Unclassified}
\def\SFitemSIXTEENbVALUE{Unclassified}
\def\SFitemSIXTEENcVALUE{Unclassified}
}{
\put(-564,100){\parbox[c]{0.8in}{\centering
\SFitemSIXTEENaVALUE}}
\put(-493,100){\parbox[c]{0.8in}{\centering
\SFitemSIXTEENbVALUE}}
\put(-422,100){\parbox[c]{0.8in}{\centering
\SFitemSIXTEENcVALUE}}
\normalsize
\end{picture}
\end{singlespace}
}
\newcommand\@SFitemONE[1]{\put(-564,662){#1}}
\newcommand\@SFitemTWO[1]{\put(-424,662){#1}}
\newcommand\SFitemTHREE[1]{\put(-217,662){#1}}
\newcommand\SFitemFOUR[1]{\put(-564,636){\parbox[t]{4.65in}{\raggedright#1}}}
\newcommand\SFitemFIVEa[1]{\put(-217,636){#1}}
\newcommand\SFitemFIVEd[1]{\put(-217,569){#1}}
\newcommand\SFitemSIX[1]{\put(-564,569){\parbox[t]{4.65in}{#1}}}
\newcommand\SFitemSEVEN[1]{\put(-564,485){\parbox[c]{4.65in}{\raggedright#1}}}
\newcommand\@SFitemEIGHT[1]{\put(-217,485){#1}}
\newcommand\SFitemNINE[1]{\put(-564,432){\parbox[c]{4.65in}{\raggedright#1}}}
\newcommand\SFitemTEN[1]{\put(-217,445){#1}}
\newcommand\SFitemELEVEN[1]{\put(-217,412){#1}}
\newcommand\@SFitemTWELVE[1]
{\put(-564,381){\parbox[c]{7.15in}{\setstretch{0.9}#1}}}
\newcommand\SFitemTHIRTEEN[1]{\put(-564,350){\parbox[t]{7.1in}{\raggedright#1}}}
\newcommand\SFitemFOURTEEN[1]{\put(-564,310){\parbox[t]{7.1in}{\raggedright#1}}}
\newcommand\SFitemFIFTEEN[1]{\put(-564,148){\parbox[b]{7.1in}{\raggedright#1}}}
\newcommand\SFitemSIXTEENa[1]{\def\SFitemSIXTEENaVALUE{#1}}
\newcommand\SFitemSIXTEENb[1]{\def\SFitemSIXTEENbVALUE{#1}}
\newcommand\SFitemSIXTEENc[1]{\def\SFitemSIXTEENcVALUE{#1}}
\newcommand\SFitemSEVENTEEN[1]{
\put(-352,108){\parbox[c]{0.8in}{\centering#1}}
}
\newcommand\SFitemEIGHTEEN[1]{\put(-285,108){\parbox[c]{0.8in}{\centering#1}}}
\newcommand\SFitemNINETEENa[1]{\put(-217,124){#1}}
\newcommand\SFitemNINETEENb[1]{\put(-217,100){#1}}


As you can see, it uses the native picture environment of LaTeX, in which it overlays your text on top of a blank form (the blank form is imported as a graphic). In your document, you then need to call on the environment to draw the picture:

%% OPTION I: CREATE YOUR OWN SF298 in LaTeX:
\begin{createSFtwoNINEeight}
% SFitemONE AUTOMATICALLY FILLED IN (\pubdate)
% SFitemTWO AUTOMATICALLY FILLED IN (Final)
\SFitemTHREE{January 2011-October 2011}
\SFitemFOUR{Frontiers in Anisotropic Shock-Wave Modeling}
\SFitemFIVEd{AH80}
\SFitemSIX{Alexander A. Lukyanov\\Steven B. Segletes}
\SFitemSEVEN{Abingdon [EDITED OUT]}
% SFitemEIGHT AUTOMATICALLY FILLED IN (\arlrptno)
%  \SFitemNINE{As needed...}
% SFitemTWELVE AUTOMATICALLY FILLED IN (\distribution)
\SFitemTHIRTEEN{[EDITED OUT].}
\SFitemFOURTEEN{
Studies of anisotropic materials and the discovery of various novel and
to our understanding of the behavior of condensed matter. The variety of
experimental studies for isotropic materials displays systematic
patterns, giving basic insights into the underlying physics of
anisotropic shock-wave modeling. There are many similarities and
significant differences in the phenomena observed for isotropic and
anisotropic constitutive equations must represent, mathematically and
physically, the generalization of the conventional constitutive equations for
isotropic material and reduce to the conventional constitutive equations
in the limit of isotropy. This report presents the current state of the
art in the experimental and theoretical developments of this fascinating
field.
}
\SFitemFIFTEEN{anisotropic material, anisotropic
plasticity, shock waves, equation of state, stress decomposition}
% \SFitemSIXTEENa defaults to UNCLASSSIFIED
% \SFitemSIXTEENb defaults to UNCLASSSIFIED
% \SFitemSIXTEENc defaults to UNCLASSSIFIED
\SFitemSEVENTEEN{UU}
\SFitemEIGHTEEN{72}%  = FRONT MATTER PP. + REPORT PP. + 2
\SFitemNINETEENa{Steven B. Segletes}
\SFitemNINETEENb{[EDITED OUT]}
\end{createSFtwoNINEeight}


The net result is

In response to the request for a self-contained example, I took the questioner's image at the top of this page, and saved it (as form.png). I then wrote this abbreviated snippet

\documentclass{article}
\usepackage{graphicx}
\usepackage{setspace}
\newenvironment{myForm}{
\clearpage
\begin{singlespace}
\begin{picture}(600,500)(70,82)
\includegraphics[height=9in]{form}
\footnotesize
\SFitemONE{\pubdate}
\SFitemEIGHT{\rptno}
}{
\normalsize
\end{picture}
\end{singlespace}
}
\newcommand\SFitemONE[1]{\put(-138,585){#1}}
\newcommand\SFitemEIGHT[1]{\put(-410,500){\textbf{#1}}}
\newcommand\SFitemSEVENTEEN[1]{
\put(-400,270){\parbox[c]{4.8in}{#1}}
}
\begin{document}
\def\pubdate{\today}
\def\rptno{xyz-123}
\begin{myForm}
\SFitemSEVENTEEN{This is the extended text  This is the extended text
This is the extended text  This is the extended text  This is the
extended text  This is the extended text  This is the extended text  }
\end{myForm}
\end{document}


The result is as follows, where a report number, a date, and an extended text section have been added to the user's form. In this example, I use both the environment to add data (\SFitemSEVENTEEN) as well as using previously defined data (\pubdate and \rptno) within the form

• Could you please extend this code snippet in such a way that it is self-contained? – user26372 Apr 12 '13 at 20:57
• @user26372 done. – Steven B. Segletes Apr 13 '13 at 12:37
• Nice approach for dealing with lots of forms, I like it! Could you comment on using the {picture} environment vs. textpos for the absolute placement? Any reason (other than familiarity) you didn't do the latter? – alexis Apr 16 '14 at 12:11
• @alexis It was purely a question of familiarity. I am unfamiliar with textpos. If I were to re-do it today, I might even try something like my answer at tex.stackexchange.com/questions/169808/… . – Steven B. Segletes Apr 16 '14 at 12:27

Just some tips,

1. Use minipages and use a key-value interface for entering the data. Entering data when you have 10 minutes to get a form out for a late report that gets lost in an avalanche of LaTeX commands is confusing and error prone. Think of minipages as divs if you familiar with html is the same concept.
2. Get to know thy minipages. You will have to use the full form of the commands, i.e., catering for outer and inner alignment as well as specifying the height of the box.
3. Use fbox when prototyping, but you may want to use rules in the final version.
4. Budget at least 1-2 hours to get a form perfect. TikZ can be your friend too, if you familiar with it. In case anyone asks for round corners.

I normally use PGF for keys. Here is a MWE

\documentclass{article}
\usepackage{pgf}
\newcommand\setform{\pgfqkeys{/form }}
\setform{field1/.store in=\fieldi,
field2/.store in=\fieldii,
}

\begin{document}

\newcommand\myform{%
\fboxrule=0.4pt
\fbox{\begin{minipage}{\textwidth}
\fbox{\begin{minipage}[t][3cm][t]{0.25\textwidth}
\textbf{Name} \fieldi
\end{minipage}}%
\fbox{\begin{minipage}[t][3cm][t]{0.4\textwidth}
\textbf{Subject} \fieldii
\end{minipage}}
\fbox{\begin{minipage}[t][3cm][t]{0.25\textwidth}
test
\end{minipage}}
\end{minipage}}
}

\setform{field1 = G. Wales,
field2 = Mathematics}
\myform

\end{document}

• While the \pgfkeys macro seems nice, in order to have it defined you need to \usepackage{pgf}. If you're not already using this package, how much will you by doing so slow down the compilation? – StrawberryFieldsForever Apr 19 '13 at 15:02
• @StrawberryFieldsForever It will slow the compilation, probably by 10 seconds. The \setform will speed up the data capturing by probably 5 minutes for a complicated form. You win some you lose some. – Yiannis Lazarides Apr 19 '13 at 15:22
• How can the data capturing take so long time? Is that true even if you write macros for setting each individual parameter that the form uses? – StrawberryFieldsForever Apr 19 '13 at 15:33
• @StrawberryFieldsForever That is from my own experience, if you have a lot of fields, even if they are macros. Try both approaches and see what is best for you. – Yiannis Lazarides Apr 19 '13 at 15:54
• Do you know how the space between the fboxes are calculated? In the code you provided (in the myform environment), there is no space between the first two of the three fboxes (which are surrounded by the larger one), but there is a small space between the last two of them. When I remove the %-symbol after the first one though there becomes a small space between the first two as well. Why is that? I thought TeX ignored whitesspaces after macro calls. – StrawberryFieldsForever Apr 19 '13 at 17:14

Use table environment with combination of minipage environment in columns and you will get it. You need to consider multicolumn and multirow packages to make this format happen.

Another solution is to check baposter for LaTeX posters. It is very optimized to create such strange layouts. Create a PDF with it and include it in your LaTeX document.

• I was thinking along the lines of minipages and frame them, but it gave me the willies... – vonbrand Apr 12 '13 at 17:43

Using floating elements or minipages has the disadvantage Latex still can alter the layout. Which is normally a good thing, but not with forms which must follow exact dimensions.

I use PGF/Tikz which let you put anything exactly where you want it, on a page.

Although it is a kind of brute force (I want !that! exactly !there!) it creates just the layout you need. Latex styles are fully preserved, and all macros are accessible.

The options for nodes are infinite so I added only the most basic ones here. Inserting graphics is equally easy.

\documentclass[a4paper]{article}
\usepackage{tikz}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[remember picture, overlay]
\node at (current page.south west){%
\begin{tikzpicture}[remember picture, overlay]
\draw (25mm,250mm) node [draw, anchor = south west, text width = 10 cm, minimum height = 3 cm]
{Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum } ;
\draw (135mm,250mm) node [draw, anchor = south west, text width = 3 cm, minimum height = 3 cm] {};
\end{tikzpicture}
};
\end{tikzpicture}
\end{document}


• My bad. I used background for creating those boxes at random places on pages in the entire document. For just one page you don't need that. I have edited my anwer accordingly. – jlinkels Sep 10 '15 at 23:23