0

The context

I want to computationally generate 1920x1080 PNG images containing text with different styles. Because LaTeX has rich features for styling text and documents can be compiled using the command line (therefore, it is convenient to create scripts), I decided to use LaTeX.

I want to create three areas with the same height arranged vertically and show a sentence in the center of those areas. The following image was created using Inkscape and it shows the result that I'm looking for.

enter image description here

What I've tried

The following minimal working example shows one of my attempts to accomplish the desired result.

\documentclass[aspectratio=169]{beamer}

\setbeamersize{text margin left=0mm,text margin right=0mm} \setbeamertemplate{navigation symbols}{} \setbeamercolor{background canvas}{bg=yellow}

\begin{document} \begin{frame} \begin{center} This is a sentence in the first area. \end{center} \par\noindent\rule{\textwidth}{1pt} \begin{center} This is a sentence in the second area. \end{center} \par\noindent\rule{\textwidth}{1pt} \begin{center} This is a sentence in the third area. \end{center} \end{frame}

\end{document}

enter image description here

The problem with this document is that the three areas are not of the same size and that the sentences are not centered.

What I know

I know that it is possible to create 1920x1080 PNG images from PDF files using convert.

$ convert -quality 100 -density 300 -resize 1920x1080 document.pdf document.png

We can use ffprobe to confirm the desired dimensions.

$ ffprobe -v error -show_entries stream=width,height -print_format default=nw=1 document.png
width=1920
height=1080
rdrg109
  • 565

2 Answers2

2

You could use minipages of fixed height:

\documentclass[varwidth=16cm]{standalone}

\setlength{\fboxsep}{0pt} \newlength{\myheight} \setlength{\myheight}{\dimexpr3cm-2\fboxrule}

\usepackage{xcolor} \pagecolor{yellow}

\begin{document}

\nointerlineskip \hskip-\fboxrule\fbox{\begin{minipage}[c][\myheight]{16cm} \centering This is a sentence in the first area. \end{minipage}}%

\nointerlineskip \hskip-\fboxrule\fbox{\begin{minipage}[c][\myheight]{16cm} \centering This is a sentence in the first area. \end{minipage}}%

\nointerlineskip \hskip-\fboxrule\fbox{\begin{minipage}[c][\myheight]{16cm} \centering This is a sentence in the first area. \end{minipage}}%

\end{document}

enter image description here

1

You could use TikZ:

\documentclass[aspectratio=169]{beamer}

\setbeamertemplate{navigation symbols}{} \setbeamercolor{background canvas}{bg=yellow}

\usepackage{tikz} \usetikzlibrary{calc}

\begin{document} \begin{frame} \begin{tikzpicture}[remember picture,overlay] \draw ($(current page.north west)!0.33!(current page.south west)$) -- ($(current page.north east)!0.33!(current page.south east)$); \draw ($(current page.north west)!0.66!(current page.south west)$) -- ($(current page.north east)!0.66!(current page.south east)$); \node[text width=\linewidth,align=center] at ($(current page.north)!0.1667!(current page.south)$) {sentence 1}; \node[text width=\linewidth,align=center] at ($(current page.north)!0.5!(current page.south)$) {sentence 2}; \node[text width=\linewidth,align=center] at ($(current page.north)!0.8333!(current page.south)$) {sentence 3}; \end{tikzpicture} \end{frame}

\end{document}

enter image description here