Layout of business cards in LaTeX

Good day to all!

There are already a lot of articles on the habr about how and where layout is used in LaTeX. From standard scientific articles and presentations to calendars and resumes.

The main advantage of LaTeX was originally the release of the writer from the need to think about the location of the text on the page: the author writes the content, and the engine places everything in the right places.

Hence the irresistible desire to start drilling with a saw and sawing with a drill bit to solve with LaTeX a task requiring complete control of the location of the text on the page. A classic example is the layout of business cards, which we will do.

Immediately make a reservation that we will not be engaged in design development - someone has already chosen for us all the indents, fonts, leading, etc., etc. We just translate this TK into the LaTeX template.

Assume that TK is as follows:

• University logo: image height 20.6 mm, the upper left corner is 4.2 mm from both the upper left corner of the card in both coordinates
• Laboratory logo: image height 20.6 mm, the upper right corner is 4.2 mm apart from the
upper right corner of the card in both coordinates
• Text color in RGB: (00.62.92)
• Background color - text color diluted with white by 50% (or RGB (00.31, 46))
• The text with the name and surname is in Arial font: size 12, leading 14.4. It is located immediately below the logos, the indent from the left edge is 18.5mm, the margin on the right is 4.2mm.
Under it with a new line the text with the post, Arial, size 7, leading 7.5
• Text with the name of the laboratory, telephones and address: Consolas, size 5.5, leading 7.5. The left margin is 18.5mm, the bottom margin is 4.2mm, the margin on the right is 4.2mm
• Reverse side of the business card: full-width university logo centered vertically and horizontally

So let's go. First you need to choose a compiler: latex and pdflatex (actually, in a sense, it's the same thing, but it doesn’t matter for this article) we don’t need non-native fonts to digest very, very badly. If someone wants to make friends with pdflatex and, say, the Myriad font, then the number of necessary gestures will go beyond all reasonable limits. XeLaTeX can work with any fonts and understands Unicode, but we don’t need anything else.

\documentclass{article}
\usepackage{fontspec}


The type of document is, in principle, unimportant to us, anyway, we will arrange the elements on the page bypassing standard mechanisms. We need the fontspec package to work correctly with otf fonts and, among other things, it allows you to easily adjust the font size and leading (more on this below).

Next item: how to solve the issue with the size of the page. The geometry package comes to the rescue, which does a great job of this.

\usepackage{geometry}

Finally, a key subtask: how to control the position of text blocks on a page, in particular, margins from fields. To do this, we will use the textpos package:

\usepackage[absolute]{textpos}

The package is connected with the absolute option, that is, the positioning of the blocks will be in absolute units.

The adjustbox package is also useful to us - this is one of the ways to control the position of images (and generally the so-called boxed content):

\usepackage[export]{adjustpage}

We use the export option so that the standard package commands apply to \ includegraphics.

Finally, the xcolor package, as we want to introduce our own colors.
\usepackage{xcolor}

Now let's configure all the packages:

\geometry{paperwidth=85mm, paperheight=55mm, layoutwidth=85mm, layoutheight=55mm, left=0mm, top=0mm, right=0mm, bottom=0mm}

Here, as you might guess, we set the paper size, the size of the space on which we will place the text, and the margins.

We set the main color of the text, and also define macros for phones and addresses:

\definecolor{bl}{RGB}{0,62,92}
\newcommand{\phonei}{T. +7~XXX~XXX~XX~XX - M.  +7~XXX~XXX~XX~XX}
\newcommand{\emaili}{you@domain.somewhere}
\newcommand{\urli}{www.domain.somewhere}
\newcommand{\secondlineaddress}{1, Nameless street\\* 123456, In The Middle of Nowhere, Earth}


A team
\pagecolor{bl!50!white}

sets the background color by diluting the already known “bl” color with white by 50%.

If we want to insert logos and / or pictures on our business card, then the best option would be to use vector formats. Let these files be called, respectively, LogoUni.eps and LogoLab.eps. We will place them next to our main file. In the municipality, xelatex can work out of the box with many image formats (unfortunately, svg does not belong to this list).

You can begin to translate requirements into reality:

\begin{document}%


We arrange the logo of our university so that the upper left corner of the image has coordinates (4.2 mm, 4.2 mm) and the logo height is 20.6 mm. To do this, we will use the environment:

\begin{textblock*}{width}[a,b](xcoord,ycoord)
\end{textblock*}


The decryption is quite simple: the text block with a width of width must be positioned so that at a point on the sheet with absolute coordinates (xcoord, ycoord) there is a block point with relative coordinates [a, b], which vary from zero to one. If a = 0, b = 0, then we have the upper left corner, if a = 1, b = 0, then the upper right, if a = 1, b = 1, then the lower right, and if a = 0.5, b = 0.5 is the center of our text block.

To adjust the height of the image, we simply use the standard \ includegraphics method:

\begin{textblock*}{50mm}[0,0](4.2mm,4.2mm)%
\noindent%
\includegraphics[height=20.6mm]{LogoUni.eps}%
\end{textblock*}

The \ noindent command is needed so that the engine does not insert a red line and does not spoil the indentation. I also note that the% signs at the end of each line - comments in TeX - are essentially here, since regular hyphens are treated as spaces and can harm the layout.

We proceed in a similar way with the laboratory logo: we place the upper right corner of the logo at the specified coordinates.

\begin{textblock*}{20mm}[1,0](80.8mm,4.2mm)%
\noindent%
\includegraphics[height=20mm, right]{LogoLab.png}%
\end{textblock*}

The right option in \ includegraphics aligns the image to the right edge of the text.

Then we place the block of text with the name and title immediately below the image with the logo, the indent on the left is 24.8 mm (the height of the image plus the indent of the image itself):

\setmainfont{Arial}%
\fontsize{12}{14.4}\selectfont%
\begin{textblock*}{62.3mm}[0,0](18.5mm,24.8mm)%
{\color{bl}%
\noindent\namei\\*%
\fontsize{7}{7.5}\selectfont%
\posi%
}\end{textblock*}%


The \ setmainfont command sets the font family for the main text (for more details, see the documentation for the fontspec package), and \ fontsize {x} {y} determines the font size x and leading y. The \ selectfont command applies the changes introduced by fontsize. The last command \\ * makes a soft hyphen and does not start a new paragraph.

Finally, we place the last block of text with the phones and the laboratory address with the same indentation of 18.5 mm so that from the bottom margins are 4.2 mm:

\setmainfont{Consolas}%
\fontsize{5.5}{7.5}\selectfont%
\begin{textblock*}{62.3mm}[0,1](18.5mm,50.8mm)
{\color{bl}%
\phonei\\%
E. \emaili}\end{textblock*}%


If we want to make the reverse side of a business card - or to make several business cards in one file, then the usual commands to start a new page (\ pagebreak, \ newpage, \ clearpage, \ cleardoublepage, etc.) just do not work. After all, there is no plain text on the page, so the engine believes that it is not necessary to start a new page. It is all handled as follows:

\null\newpage%

Already on the thumb, we add a picture with a logo, we place the center of the text block in the center of the paper:

\begin{textblock*}{85mm}[0.5,0.5](42.5mm,27.5mm)%
\noindent%
\includegraphics[width=85mm]%
{LogoUni.eps}%
\end{textblock*}%
\end{document}


Final document:
\documentclass{article}
\usepackage{fontspec}
\usepackage{geometry}
\usepackage{xcolor}
\usepackage[absolute]{textpos}
\usepackage{tikz}
\geometry{paperwidth=85mm, paperheight=55mm, layoutwidth=85mm, layoutheight=55mm, left=0mm, top=0mm, right=0mm, bottom=0mm}
\definecolor{bl}{RGB}{0,62,92}
\newcommand{\phonei}{T. +7~XXX~XXX~XX~XX - M.  +7~XXX~XXX~XX~XX}%
\newcommand{\namei}{Name Surname}
\newcommand{\posi}{Position}
\newcommand{\emaili}{E. you@yourdomain.somewhere}
\newcommand{\urli}{yourdomain.somewhere}
\newcommand{\secondlineaddress}{1, Nameless street\\* 123456, In The Middle of Nowhere, Earth}
\pagecolor{bl!50!white}
\begin{document}%
\begin{textblock*}{50mm}[0,0](4.2mm,4.2mm)%
\noindent%
\includegraphics[height=20.6mm]{LogoUni.eps}%
\end{textblock*}%
\begin{textblock*}{50mm}[1,0](80.8mm,4.2mm)%
\noindent%
\includegraphics[height=20.6mm,right]{LogoLab.eps}%
\end{textblock*}%
%
\setmainfont{Arial}%
\fontsize{12}{14.4}\selectfont%
\begin{textblock*}{62.3mm}[0,0](18.5mm,24.8mm){\color{bl}\noindent\namei\\*%
\setmainfont{Arial}%
\fontsize{7}{7.5}\selectfont%
\posi%
}\end{textblock*}%
\setmainfont{Consolas}%
\fontsize{5.5}{7.5}\selectfont%
\phonei\\%
\emaili}\end{textblock*}%
\null\newpage%
\begin{textblock*}{85mm}[0.5,0.5](42.5mm,27.5mm)%
\noindent%
\includegraphics[width=85mm]
{LogoUni.eps}%
\end{textblock*}%
\end{document}


I sketched logos for this article in Inkscape, picked up the colors and fonts “if only”, so I won’t vouch for the aesthetic component.

Final front and back side:

Links to documentation for used packages: