11

I was wondering if anyone ever tried to typeset slides with a grid layout, ie. something like (see below the tikz grid showing it).

Expected functionalities:

  • ability to write text or place image across several columns on the fly (ie. provide kind of start coordinate/ size of frame containing text or image + text aligned on a grid)
  • compatibility with [c] option for frame (or similar)
  • I don't care about the crappy blocks from beamer (less is better)
  • would appreciate to get something in the vein of http://www.treesmapsandtheorems.com/barriers/

Starting point code (but no need to stick to it), where the grey block could be text and the yellow block an image:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}

\setbeamertemplate{headline}{}

\setbeamertemplate{navigation symbols}{}

\usebackgroundtemplate%
{%
    \begin{tikzpicture}[overlay,remember picture]
        \draw[step=.4cm,gray,thin] (current page.south east) grid (current page.north west);
        \draw[thick] ($(current page.north west)+(.4cm,-.4cm)$) rectangle ($(current page.north west)+(6cm,-1.6cm)$); % frametitle
       \draw[thick] ($(current page.south west)+(0cm,.4cm)$) rectangle (current page.south east); % footer
        \draw[thick] ($(current page.south west)+(1cm,.8cm)$) rectangle ($(current page.north west)+(3.4cm,-2.4cm)$);
        \draw[thick] ($(current page.south west)+(3.8cm,.8cm)$) rectangle ($(current page.north west)+(6.2cm,-2.4cm)$);
        \draw[thick] ($(current page.south west)+(6.6cm,.8cm)$) rectangle ($(current page.north west)+(9cm,-2.4cm)$);
        \draw[thick] ($(current page.south east)+(-3.4cm,.8cm)$) rectangle ($(current page.north east)+(-1cm,-2.4cm)$);
    \end{tikzpicture}
}

\setbeamercolor{footline}{fg=white,bg=black}

\begin{document}

\begin{frame}
\begin{tikzpicture}[overlay,remember picture]
    \fill[yellow] ($(current page.center)+(.2,1.6cm)$) rectangle ($(current page.east)+(-1cm,-1.6cm)$);
    \fill[gray] ($(current page.center)+(-.2,2.4cm)$) rectangle ($(current page.west)+(1cm,-2.4cm)$);
\end{tikzpicture}
\end{frame}

\end{document}

enter image description here

Note: if a ConTeXt solution is much convenient to use (less code to type), please feel free to share.

  • Do you want text to automatically reflow from one column to the next? – Aditya Jul 22 '14 at 15:10
  • @Aditya I would say that in principle a presentation (slides) is not so wordy, so it'd happen that two or more columns are "merged" to get a wider width for the text. But having text to automatically reflow isn't a priority. It'd be nice but not absolutely needed, IMO. – s__C Jul 22 '14 at 15:12
  • 1
    Why not use the columns environment of beamer? – Paul Gaborit Jul 27 '14 at 8:35
  • 1
    All types of alignment can be made via columns... What is you problem with columns? – Paul Gaborit Jul 27 '14 at 8:40
  • 1
    Did you try the [t] option of columns environment? – Paul Gaborit Jul 27 '14 at 10:18
9
+150

In ConTeXt, Layers (also see the details manual) are the canonical method for absolute positioning.

Although, you can use absolute coordinates (x=<dimen>, y=<dimen>) to position layers, for creating slides is is nicer to use relative coordinates (lines=<num>, column=<num>). To use such coordinates, use:

\setuplayout[grid=yes, columns=6, columndistance=1em]

This dives the page width into six virtual columns with a 1em gap between them. The lines and columns can be visualized using:

\showgrid

Then, you can simply place any element at a particular line and column using either

\setlayer[...][line=..., column=..., ...]{...}

or

\setlayerframed[...][line=..., column=..., ...]{...}

A complete example is as follows (this uses low-level commands; if you want to build a presentation system on top of this, you would need to define a higher-level interface):

\setuppapersize[S4]
\setuppagenumbering[location=]

\setuplayout[page] % Choose a layout with 0 margins
\setuplayout[grid=yes, columns=6, columndistance=1em]

% The layer to place the content
\definelayer[text]
\setupbackgrounds[page][background={foreground,text}]

\showgrid % To visualize the layout

\starttext

% Place the upper left corner of the title at
% line 1 column 2

\setlayerframed
    [text]
    [
      line=1,
      column=2,
      frame=off,
      foregroundstyle=\ssc,
      foregroundcolor=blue,
    ]
    {Slide title}

% Place a box that is two columns wide with some text
% at line 6 column 2

\setlayerframed
  [text]
  [
    line=6,
    column=2,
    width=\the\dimexpr2\layoutcolumnwidth+\layoutcolumndistance\relax,
    align={normal,verytolerant, stretch},
    framecolor=blue,
    rulethickness=2pt,
    corner=round,
  ]
  {This is where paragraph starts. The text goes on and on. 
   Since the text width is given, it will wrap to the next line automatically.
   The origin is anchored at the center where the red start is located \unknown}

% Place an image at line 10, column 5

\setlayer
  [text]
  [
    line=10,
    column=5,
  ]
  {\externalfigure[http://placekitten.com/g/300/550][method=jpg]}

\null \page

\stoptext

The \null \page is necessary, otherwise the layer will not be flushed.

The output is:

enter image description here

For the actual presentation, comment out the \showgrid to get:

enter image description here

  • why isn't the slide title on the grid? Because of the bigger fontsize? Another question: is it possible to resize an image with lines height & columns width? – s__C Jul 29 '14 at 5:59
  • I placed the "top-left" corner of the slide title is at the line. Placing the baseline of the title to the grid is more tricky. If you want to do that, it is easier to place the content using the section heads. See the details manual for different options on aligning section heads to the grid. – Aditya Jul 29 '14 at 6:40
  • 1
    To resize images use: \externalfigure[name][width=\layoutcolumnwidth, height=6\lineheight] etc. But keep in mind that this will change the aspect ratio of the image. It is better to specify only the width or the height, and let ConTeXt automatically scale the other dimension to maintain the aspect ratio. – Aditya Jul 29 '14 at 6:42
3

This is a proposal. The absolute position in tikz is utilized here.

A) Define 5 corners as (A) (B) (C) (D) (CC) respectively via

\node[] (label) at (current page.<anchor position>){ };

Then current page.center is chosen as the origin for absolute positioning. (More detail explanation is written in the brown box).

B) Place nodes at proper positions via

\node [xshift=xxcm,yshift=yycm] at (CC) [text width=5cm,text opacity=1, 
 draw=brown,line width=2pt,rounded corners]{text contents}

where

the first option [...] is for absolute position via xshift=xx, yshift=yyw.r.t (CC) -- Coordinate Center. Note that anchor=center is default for ease of alignment. This means that one can put any node around the the origin (CC) once the coordinate (xx,yy) is determined.

the second option [...] is to specify text width and/or draw/fill box with colors. In this example, 4 blocks (header,footer,text box,image) are demonstrated.

C) Fill an area connected by line and curve (X) to[out=90,in=180] (Y) with orange having some opacity=0.x

enter image description here enter image description here

Code

%\PassOptionsToPackage{demo}{graphicx}
\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{calc}

\setbeamertemplate{headline}{}

\setbeamertemplate{navigation symbols}{}

\usebackgroundtemplate%
{%
\begin{tikzpicture}[overlay,remember picture,opacity=0.5]
\node[] (A) at (current page.south east){ };
\node[] (B) at (current page.north west){ };
\node[] (C) at (current page.south west){ };
\node[] (D) at (current page.north east){ };
\node[red] (CC) at (current page.center){*};
\draw[step=.4cm,gray,thin] (A) grid (B);     % Use 0.5cm will be easier to find coordinates (xx,yy)
\end{tikzpicture}
}
\setbeamercolor{footline}{fg=white,bg=black}

\begin{document}

\begin{frame}[c]
\begin{tikzpicture}[overlay,remember picture]
\node[] (A) at (current page.south east){ };
\node[] (C) at (current page.south west){ };
\node[red] (CC) at (current page.center){*};

\node [xshift=-3cm,yshift=4cm] at (CC)
[text width=5cm,fill=green!20,thick,rounded corners,align=center]{This is where the title is.};

\node [xshift=-3cm,yshift=0cm] at (CC) [text width=5cm,text opacity=1,draw=brown,line width=2pt,rounded corners]{This is where paragraph starts.
The text goes on and on. Since the text width is given, it will wrap to the next line automatically. The origin is anchored at the center where the red star is located. Why? So that the coordinates (x,y) for the 4 quadrants are easily identified and the coordinate can be obtained correctly. Furthermore, all nodes are, by default, anchored at center. This will make alignment easier};

\node [xshift=3cm,yshift=0cm] at (CC)
[text width=4cm,draw=red,line width=2pt,rounded corners]
{\includegraphics[width=4cm,height=4cm]{abc}};

\node [xshift=0cm,yshift=-4.5cm] at (CC)
[text width=12cm,text opacity=1,fill=blue,line width=2pt,rounded corners, align=center] {This is where the footer is};

\fill[fill opacity=0.3,orange] ($(C)+(1cm,0)$) to[out=90,in=180] ($(A)+(0,8cm)$) --($(A)+(0,-5cm)$) --cycle;
\end{tikzpicture}
\end{frame}

\begin{frame}[c]
\frametitle{Continued}
\end{frame}

\end{document}
  • The text will never be aligned on the grid. Plus it's even worst when there is an itemize inside the block of text. – s__C Jul 27 '14 at 6:13
  • @s__C Thanks for the feedback, I will check again. In the mean time, please understand that they are tikz nodes and this links tex.stackexchange.com/q/123671/34618 has many alignment skills summarized, including itemize. – Jesse Jul 27 '14 at 8:36
  • @s__C -- I just made a new node with item list. Please take a look by inserting the snippet into the code, requiring 2 compilations for proper output \node [xshift=3cm,yshift=3.4cm] at (CC) [text width=3cm,text opacity=1, draw=none, line width=2pt,rounded corners]{ \begin{description}[style=nextline] \item[1.] description 1 \item[2.] description 2 \item[3.] description 3 \end{description} }; – Jesse Jul 27 '14 at 8:43
3

There is a new package to produce slides based on a grid system: gridslides. A short introduction can be found at https://github.com/minad/gridslides

It contains different types of objects (for figures, blocks ...) which will placed by specifying their x-y-coordinated and width.

A short example:

\documentclass{gridslides}

\usepackage{lipsum}

\begin{document}

\begin{slide}{Overview}
\fig(5,1,15){example-image}
\block(1,15,27){\footnotesize\lipsum[2]}
\end{slide}

\end{document}
3

Another alternative to obtain something like a grid system on beamer slides could be tcbposter (from tcolorbox). A tcbposter divides its space into an array with certain number of columns and rows, and these references are used to place tcolorboxes. These boxes can span several columns and rows (even not in integer proportions) or use the vertical space between two previously defined boxes. For more verbose boxes, text can flow between several boxes.

Information about this library can be found in nineteenth chapter of tcolorbox documentation but also into this nice tutorial.

Following code shows a little example applied over a beamer slide. Some other examples can be found here in: Creating this poster layout using minipages or Dynamic box size

\documentclass{beamer}
\usepackage[most]{tcolorbox}
\usepackage{lmodern}
\begin{document}
\begin{frame}
\begin{tcbposter}[%
    coverage = spread,
    poster = {showframe, columns=4, rows=5}
]
\posterbox{name=title, column=1, span=3, below=top}{This is the slide title}
\posterbox{name=text, column=1, span=2.5, row=3, rowspan=2}{Some nice explanation}
\posterbox[title=A frog, valign=center]{name=image, column*=4, span=1.5, between=title and bottom}{\includegraphics[width=\linewidth]{frog}}

\end{tcbposter}
\end{frame}
\end{document}

The result shows (due to showframe option) the division structure over the slide and also the different posterboxes placed on it. As you can imagine, boxes aspect can be individually defined with all tcolorbox flexibility.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.